使用以下管道作业时,我收到语法错误。
Found errors in your .gitlab-ci.yml:
jobs:test-artifact:script config should be a string or a nested array of strings up to 10 levels deep
You can also test your .gitlab-ci.yml in CI Lint
有人建议将 : 部分保留在双引号中,但它已经是其中的一部分了。
test-artifact:
stage: build
allow_failure: false
needs: ["build-rpm"]
dependencies: # This is what gets the artifacts from the previous job
- build-rpm
extends:
- .ifadmindeploy
image: ubuntu:latest
script:
- yum update -y && yum install -y curl
- echo $CI_JOB_TOKEN
- mkdir test && cd test
- curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://myproject.gitlab.io/-/product/-/jobs/${CI_JOB_ID}/artifacts"
- curl --location --output artifacts1.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/myproject/product/-/jobs/${CI_JOB_ID}/artifacts"
- curl --location --output pipeline.rpm --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/myproject/product/-/jobs/${CI_JOB_ID}/artifacts/raw/dist/myproject-dev-default-nightlye2e.x86_64.rpm"
- curl --location --output pipeline.rpm --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://myproject.gitlab.io/-/product/-/jobs/${CI_JOB_ID}/artifacts/raw/dist/myproject-dev-default-nightlye2e.x86_64.rpm"
- ls -la
答案1
如果用“ ”括号将整个命令括起来,应该可以解决问题。
类似下面的内容:
'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://myproject.gitlab.io/-/product/-/jobs/${CI_JOB_ID}/artifacts"'
请记住,如果您已经在命令中使用“ ”括号,这将不起作用,仍在研究如何解决这个问题!
答案2
您可以使用管道符号“|”,例如:-
script:
- yum update -y && yum install -y curl
- echo $CI_JOB_TOKEN
- mkdir test && cd test
_ |
curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://myproject.gitlab.io/-/product/-/jobs/${CI_JOB_ID}/artifacts"