My Jenkins Pipeline needs to run some git commands after SSHing into a server using the sshPublisher. In my pipeline I’m extracting the commit message and saving it to “GIT_COMMIT_MSG” and after SSHing into the server i’m running “git commit -m $GIT_COMMIT_MSG”.
Here my git commit message is not executing successfully and throwing empty message error. So that means after SSHing into server the shell is not aware of my GIT_COMMIT_MSG variable. but when i’m printing that variable outside of the SSH block it’s giving me the correct commit message.
How can i make my shell aware about the GIT_COMMIT_MSG. What is the best way to do that. The below are the snippets from my pipeline script. Please let me know where i’m doing wrong and what is the best method to achieve my goal.
In my pipeline checkout stage i’m running this command to get the commit message
“GIT_COMMIT_MSG = sh (script: “git log -1 --pretty=%B --first-parent origin/${params.branch}”, returnStdout: true).trim()”
The below is my sshPublisher block
sshPublisher(publishers: [sshPublisherDesc(configName: ‘meow-aws-wdxq2’,
sshCredentials: [encryptedPassphrase: ‘XXXXXXXXXXXXXXX’, key: ‘’, keyPath: ‘’,
username: ‘prudhvi.mallina’], transfers: [sshTransfer(cleanRemote: false, excludes: ‘’, execCommand: ‘’‘echo $USER > /tmp/angular.log 2>&1
cd /controller/webapp/ag-wms
echo “Hii” >> /tmp/angular.log 2>&1
echo “Commit message: ‘$GIT_COMMIT_MSG’” >> /tmp/angular.log 2>&1
git add . ‘’’,
execTimeout: 620000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false,
patternSeparator: ‘[, ]+’, remoteDirectory: ‘’, remoteDirectorySDF: false, removePrefix: ‘’, sourceFiles: ‘’)],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
sh “echo $GIT_COMMIT_MSG”
Thanks,
Prudhvi M.