curl - 如何在 gitlab-ci 文件中使用 curl?
问题描述
在我的 gitlab-ci 文件中,我想使用命令curl
来获取页面的结果并验证其内容,但我不知道如何使用它。
....................
server:check-quality:
<<: *all-settings
stage: check-quality
<<: *tags_definition
script:
- echo "APPEL de CURL"
- content=($curl http://example.com/sonar/api/qualitygates/project_status?projectKey=com.orange.catalog:feature-m752-conditionequals)
- echo "content"
- exit 0
only:
- develop
- /^feature.*$/
- /^hotfix.*$/
请问你有什么想法吗?
解决方案
我不太确定这会奏效;因为 YAML 解释器会吞噬各种特殊字符,例如该 http 中的 :。在经过数小时的努力后使其工作,这是我找到的解决方案。
- |
curl --fail --output "/dev/null" --silent --show-error --write-out "HTTP response: ${http_code}\n\n" \
--data "{\"tag_name\": \"${CI_COMMIT_TAG}\", \"name\": \"${CI_PROJECT_NAME} ${CI_COMMIT_TAG}\", \"description\": \"${CI_COMMIT_TAG_MESSAGE:-No release notes.}\"}" \
--header "Content-Type: application/json" \
--header "Private-Token: ${CI_PRIVATE_TOKEN}" \
--request POST \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases"
这个脚本将使用 gitlab api 生成一个版本,所以比你所要求的更花哨。
请注意,CI_COMMIT_TAG_MESSAGE 是我的变量,希望将其添加到 GitLab。
最大的问题是找出所有需要转义的特殊字符。
此外,您在内容参数中交换了 ( 和 $ ;)
推荐阅读
- functional-programming - 按 OCaml 中的键过滤对列表
- python - Telegram bot 的此代码可以工作,因为我复制了它,但没有
- angularjs - 如何检查 react-router 是否在上下文中?
- apache-spark - 如何在 Spark 提交作业中传递 Kerberos keytab+principal 以验证 Spark 和 Yarn?
- c# - 将@Url.Action 存储在变量中
- android - ArrayIndexOutOfBoundsException:长度=12;index=-1 from delete position from alert对话框
- python - 按钮背景显示但没有图像并且它不起作用
- firebase - 我从 Firestore 中的数据无法使用 dart Flutter 检索
- javascript - 旋转照片时可调整大小的照片在对角线而非 x 轴上展开
- swift - 显示标签的数组问题