I am having a syntax error when I test my gitlab-ci.yml in CI Lint. Can someone suggest a solution to this problem?
build-production:
stage: build
only:
- master
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
rules:
- if: $CI_COMMIT_TAG
Status: syntax is incorrect
jobs:build-production config key may not be used with `rules`: only
These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.
It might be a security vulnerability The code in your most recent commit could be vulnerable, or a dependency could be at risk, either of which would trigger a failed security test and thus a failed pipeline.
The limit keyword limits the number of jobs that can run simultaneously in a job stream. This keyword works only if all the jobs in the job stream are defined on workstations that are managed by the same batchman process.
CI_COMMIT_TAG - The commit tag name. Present only when building tags. Therefore in the variables section CI_COMMIT_TAG is not defined, hence equals to "". So if you want to use CI_COMMIT_TAG use in job where tags are defined.
Documentation is pretty clear :
rules
replacesonly
/except
and they can’t be used together in the same job. If you configure one job to use both keywords, the linter returns a key may not be used with rules error.
I suggest to use rules:
for both of your conditions :
rules:
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_COMMIT_TAG'
This is not correct, unless you would create a tag master
.
See: https://gitlab.sron.nl/help/ci/variables/predefined_variables.md
CI_COMMIT_REF_NAME
The branch or tag name for which project is built.
There is a workaround described here: Gitlab CI: Run Pipeline job only for tagged commits that exist on protected branches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With