0

I have the following strings: deploy_tag and version_number .

deploy_tag can be "2.8.6.1" or "origin/master" and version_number can only be numeric separated by dots like "1.1.2.3".

I want to do something like that:

if [[ $deploy_tag == *["\/"+]* ]]; then deploy_tag=$version_number; fi

Meaning: If $deploy_tag contains "/" then set it's value with the value of $version_number.

This whole shell script is part of a shell execution within a Jenkins job.

The problem is that seems like something is wrong with my regex but I can't find what... can you?

I checked some other questions on stackoverflow but I couldn't find the issue with my regex.

Edit #1: Here's an example from Jenkins build log:

[social-portal] $ /bin/sh -xe /tmp/hudson1162745529550311655.sh
+ [[ origin/master =~ / ]]
/tmp/hudson1162745529550311655.sh: 2: /tmp/hudson1162745529550311655.sh: [[: not found
+ echo deploy: origin/master
deploy: origin/master
+ echo version: 2.7.4
version: 2.7.4
+ mkdir output

And that's the code which generates the problem (including debug echo's):

if [[ $DEPLOY_TAG =~ / ]]; then DEPLOY_TAG=$VERSION_NUMBER; fi
echo deploy: $DEPLOY_TAG
echo version: $VERSION_NUMBER
0

1 Answer 1

0

Jenkins is using /bin/sh, which you cannot assume is bash. Even if /bin/sh is a link to some version of bash, some bash features may not work properly. You need to use a POSIX-compatible construct.

case $deploy_tag in
  */* ) deploy_tag=$version_number ;;
esac
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.