Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Run shell script

gmuselli August 2, 2017

Hello,

 

I try to automate the tag creation with pipeline.

I built a shell script which seems to work on local. However it makes pipeline fail.

Here is my pipeline:

# This is a sample build configuration for Java (Maven).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: maven:3.3.9

pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn clean package -Denv=uat
branches:
master:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn clean package -Denv=uat
- sh tag.sh

 

The shell script:

#!/bin/sh

# retrieve branch name
BRANCH_NAME=$(git branch | sed -n '/\* /s///p')

# remove prefix release
REGEXP_RELEASE="release\/"
VERSION_BRANCH=$(echo "$BRANCH_NAME" | sed "s/$REGEXP_RELEASE//")

echo "Current version branch is $VERSION_BRANCH"

# retrieve the last commit on the branch
VERSION=$(git describe --tags --match=$VERSION_BRANCH* --abbrev=0)

# split into array
VERSION_BITS=(${VERSION//./ })

#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
VNUM2=${VERSION_BITS[1]}
VNUM3=${VERSION_BITS[2]}
VNUM3=$((VNUM3+1))

#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"

echo "Updating $VERSION to $NEW_TAG"

#get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT`

#only tag if no tag already (would be better if the git describe command above could have a silent option)
if [ -z "$NEEDS_TAG" ]; then
echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
git tag $NEW_TAG
git push --tags
else
echo "Already a tag on this commit"
fi

When I remove the line with sh tag.sh I do not have issues. However when I add it I have the pipeline build in failure but no logs.

The shell script is at the root of my project. Do you have any idea?

 

Thanks in advance 

1 answer

0 votes
gmuselli August 2, 2017

Found the solution I changed my script to bash

Then added this to my pipeline

 

- chmod +x tag.sh
- ./tag.sh

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events