Check tag is correct version in GitLab-CI pipeline

Viewed 28

When a new tag is created I want to validate in the pipeline configuration that the new tag version is correct and the same than python setup.py. I added this script to the pipeline but looks like is not working.

script:
- VERSION=$(python setup.py --version)
- if [ $CI_COMMIT_TAG != $VERSION ]; then
- echo "Tag does not match the correct version"
- exit 1; fi
1 Answers

You can't split bash if/then statements across multiple script array items in GitLab CI. You must either do it all in one line or use a multiline string for the array item.

script:
  - version=$(python setup.py --version)
  - |
    if [[ "${CI_COMMIT_TAG}" != "${version}" ]]; then
        echo "Tag '${CI_COMMIT_TAG}' does not match the expected version '${version}'"
        exit 1
    fi
  - echo "OK"
Related