I'm trying to commit some files in separate commits in a Jenkins Pipeline using the following code:
sh '''
git add $SOURCE_ENV/metadetail/current/*
git commit -m "Updating Snapshot Metadata"
git add $SOURCE_ENV/release/*
git commit -m "Package for Release Branch"
git push -u origin HEAD:$BRANCH_NAME
git checkout master
git checkout -b $BRANCH_NAMEfb
git cherry-pick $BRANCH_NAME
git push -u origin HEAD:$BRANCH_NAMEfb
'''
The aim here is to do 2 separate commits on the current branch, create a new feature branch from master, then cherry-pick the 2nd commit from original branch onto the new branch. This is failing the jenkins build following the first commit, with the following message:
+ git commit -m Updating Snapshot Metadata
HEAD detached from 4b8ea1e
Untracked files:
dPATCH/release/
nothing added to commit but untracked files present
script returned exit code 1
I'm not certain what is going on - my understanding is that only files in 'staging' are important when committing so not sure why the other files are being picked up when I'm only initially running git add on a subset of the files. Any ideas?