如何在gitlab-ci文件中使用curl?

问题描述 投票:1回答:2

在我的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.*$/

你有什么想法吗?

curl gitlab-ci
2个回答
2
投票

在脚本中你可以使用curl之类的

script:
  - echo "APPEL de CURL"
  - curl http://example.com/sonar/api/qualitygates/project_status?projectKey=com.orange.catalog:feature-m752-conditionequals
  - echo "content"
  - exit 0

0
投票

我不太确定这会起作用;因为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中。

最大的问题是弄清楚所有需要逃避的特殊角色。

另外,你交换了你的内容参数中的$(和$;)

© www.soinside.com 2019 - 2024. All rights reserved.