awk doesnt work as expected
Summary
I'll try parse with regexp name of branch and create tag with version based on result vars
Steps to reproduce
Full copy of tag stage
tag:
# only:
# refs:
# - merge_requests
# variables:
# - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^release-.*$/
# except:
# refs:
# - tags
stage: tag
image: debian:stable
before_script:
- apt-get clean -qq
- apt-get update -qq --fix-missing
- apt-get install -qq --fix-missing git
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $MY_GIT_URL >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- result=($(echo $CI_COMMIT_REF_NAME | awk '{match($0,/([0-9])+.([0-9])+.([0-9])+(-[a-zA-Z0-9]+)?/,a);print a[1],a[2],a[3],a[4]}'))
- patch=($(git rev-list --no-merges --count HEAD))
- minor= expr $(git rev-list --count HEAD) - $patch
- VERSION="${result[1]}.${minor}.${patch}${result[4]}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git remote set-url origin "${SSH_GIT_URL}"
script:
- git tag -a "v${VERSION}" ${CI_COMMIT_SHA} -m "${VERSION}"
- git push origin --tags
- git checkout -b release-${VERSION}
- git push -u origin release-${VERSION}
Actual behavior
$ chmod 644 ~/.ssh/known_hosts
$ echo $CI_COMMIT_REF_NAME | awk '{match($0,/([0-9])+.([0-9])+.([0-9])+(-[a-zA-Z0-9]+)?/,a);print a[1],a[2],a[3],a[4]}'
awk: line 1: syntax error at or near ,
ERROR: Job failed: exit code 1
Expected behavior
Branch name is release-1.1.0-a
Expected
$ CI_COMMIT_REF_NAME=release-1.1.0
$ echo $CI_COMMIT_REF_NAME | awk '{match($1,/^(.*)([0-9])+.([0-9])+.([0-9])+(-[a-zA-Z0-9]+)?$/,a);print a[2],a[3],a[4],a[5]}'
Environment description
I'm run gitlab ce self-hosted with own runners