It looks like you are missing an internal array and some double quotes and escaped double quotes to run the script:
sh([ script: "curl \"http://${jenkinsUser}:${jenkinsUserToken}@${jenkinsServer}:8080/job/myJob/lastBuild/consoleText\"").trim()
There are also several ways to execute shell scripts, and this depends on the type of jenkins type you are using.
In the jenkins declarative pipeline, you need to include a script {...} block script {...} for all script types and installation variables, and that would look like this:
pipeline { agent { ... } parameters { ... } environment { ... } stages { stage('Run Required Scripts') { steps { ... script { NOTIFIER_BULD_NAME = sh([script: "./getNotifier.sh", returnStdout: true]).trim() EMAIL_TEXT = sh([script: "./printEmailText.sh ${CURRENT_BUILD} ${PREVIOUS_BUILD}", returnStdout: true]).trim() BODY= sh([ script: "curl \"http://${jenkinsUser}:${jenkinsUserToken}@${jenkinsServer}:8080/job/myJob/lastBuild/consoleText\"").trim() } } } stage('Send Email') { when { expression { // Only send when there is text. "${EMAIL_TEXT}" != ""; } } steps{ emailext ( to: 'software@company.com', subject: "You have mail - ${EMAIL_TEXT}", body: """${NOTIFIER_BULD_NAME} - ${EMAIL_TEXT}: ... ${BODY} """, attachLog: false ) } } }
In a Jenkins script, you donβt need a script{} block, you can actually place it in most places. I basically put it in the frames of the stage stage('some stage'){...} , and I did it like this:
V5_DIR = WORKSPACE + '/' + sh([script: "basename ${V5_GIT_URL} .git", returnStdout: true]).trim()
Although I also used curl commands (for script pipelines) and did not need an internal array ...
lastSuccessfulCommit = sh( script: "curl -sL --user ${JENKINS_API_USER}:${JENKINS_API_PSW} \"${lastSuccessfulCommitUrl}\" | sed -e 's/<[^>]*>//g'", returnStdout: true )
And for reference, echo-wars look like in
sh([script: "echo \"Value: ${someVariable}\""])
Hope this documentation helps too, but I know that recently Jenkins documentation can be quite spotty, so I also found a great idea on how not to do something for Jenkins declarative pipelines . Good luck