Reputation: 7550
In GitLab CI script I wanted to
So for that I have tried to use sed , but it's not working in GitLab Script (working on bash shell locally)
export BRANCH_NAME={$CI_COMMIT_REF_NAME} | sed 's/\.[^.]*$//' | sed 's/[^0-9.]//g'
any idea what is missing here ?
If sed is not going to work here then any other option to achieve the same?
Edit : As per @WiktorStribiżew - echo "$CI_COMMIT_REF_NAME" | sed 's/.[^.]$//' | sed 's/[^0-9.]//g' - export BRANCH_NAME=${CI_COMMIT_REF_NAME} | sed 's/.[^.]$//' | sed 's/[^0-9.]//g'
echo is working but export is not
Upvotes: 2
Views: 2008
Reputation: 626870
First of all, to remove all text after and including second dot you need
sed 's/\([^.]*\.[^.]*\).*/\1/'
The sed 's/\.[^.]*$//'
sed command removes the last dot and any text after it.
Next, you must have made a typo and you actually meant to write ${CI_COMMIT_REF_NAME}
and not {$CI_COMMIT_REF_NAME}
.
So, you might be better off with
export BRANCH_NAME=$(echo "$CI_COMMIT_REF_NAME" | sed 's/\([^.]*\.[^.]*\).*/\1/' | sed 's/[^0-9.]//g')
Upvotes: 0
Reputation: 11227
Using sed
$ export BRANCH_NAME=$(echo "$CI_COMMIT_REF_NAME" |sed 's/[A-Za-z]*//g;s/\([0-9]*\.[0-9]*\)\.[^ ]*/\1/g')
Upvotes: 1