Harold L. Brown Harold L. Brown - 9 days ago 5
Bash Question

Jenkins Pipeline plugin seemingly skipping commands

I have a Jenkins Pipeline plugin script looking like this:

stage("check out project") {
shell "pwd"
echo "test 1"
git credentialsId: "user", url: "http://url/project"
echo "test 2"
shell "git --version"
echo "test 3"
}


The output of the build is this:

[Pipeline] stage
[Pipeline] { (check out project)
[Pipeline] echo
test 1
[Pipeline] echo
test 2
[Pipeline] echo
test 3
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS


Judging from the output and the build time only the echo commands are executed. All others are ignored. No error seems to occur.

How can I get all commands to be executed?

Answer

your script ran successfully and worked as expected after

  1. surrounding it with node{ } and
  2. using sh intead of shell

like this:

node{
    stage("check out project") {
        sh "pwd"
        echo "test 1"
        git credentialsId: '12341234-1234-1234-1234-123412341234', url: "git@github.com:sendgrid/sendgrid-java.git"
        echo "test 2"
        sh "git --version"
        echo "test 3"
    }
}