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

前端 未结 6 1343
面向向阳花
面向向阳花 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:21

    Jenkins create a folder when it make a clone from your project like this:

    /var/lib/jenkins/workspace/job-name@script

    For this to work you must set the file as executable if you are in a linux environment and then call the shell script.

    Something like this:

    // Permission to execute
    sh "chmod +x -R ${env.WORKSPACE}/../${env.JOB_NAME}@script"
    
    // Call SH
    sh "${env.WORKSPACE}/../${env.JOB_NAME}@script/script.sh"
    

提交回复
热议问题