How do I make Jenkins 2.0 execute a sh command in the same directory as the checkout?

前端 未结 6 1329
面向向阳花
面向向阳花 2021-02-05 00:45

Here\'s my Jenkins 2.x pipeline:

node (\'master\'){
    stage \'Checkout\'
    checkout scm
    stage \"Build Pex\"
    sh(\'build.sh\')
}

When

6条回答
  •  生来不讨喜
    2021-02-05 01:23

    The reason that your script doesn't work is because "build.sh" is not in your PATH.

    The Jenkinsfile is running a "sh" script, whose entire contents is the string build.sh. The parent script is in the "@tmp" directory and will always be there - the "@tmp" directory is where Jenkins keeps the Jenkinsfile, essentially, during a run.

    To fix the problem, change your line to sh "./build.sh" or sh "bash build.sh", so that the sh block in the Jenkinsfile can correctly locate the build.sh script that you want to execute.

提交回复
热议问题