String manipulation in sh block

22 views
Skip to first unread message

Idan Adar

unread,
Sep 24, 2017, 8:27:15 AM9/24/17
to Jenkins Users
Appreciate help with getting the following block right (I always get confused with strings and double/single/escaped quotes):

Right now the below puts the message "Bump version number (${version}) [ci skip]" in the commit message.
The wanted result is for ${version} to actually be the extracted version number rather than the variable name as-is...

sshagent (credentials: ['...']) {
   sh
'''
      git clone -b master git@github.***.git
      ...
      ...
      version=$(jq \".version\" package.json | tr -d '
\"')
      git commit -am "
Bump version number (${version}) [ci skip]"
      git push origin master
   '''
}

Idan Adar

unread,
Sep 24, 2017, 9:05:31 AM9/24/17
to Jenkins Users
Okay, got it at last.
The backslashes weren't needed.

version=$(jq \".version\" package.json | tr -d '\"')


Reply all
Reply to author
Forward
0 new messages