Jenkins does not recognize command sh?

后端 未结 9 1921
心在旅途
心在旅途 2020-12-09 09:27

I\'ve been having a lot of trouble trying to get a Jenkinsfile to work. I\'ve been trying to run this test script:

#!/usr/bin/env groovy
node {
    stage(\'         


        
9条回答
  •  温柔的废话
    2020-12-09 09:54

    In order to fix this issue, in case that you can't delete the PATH global property from "Manage Jenkins -> Configure System", you should add the following step:

    withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin'])

    Like following: for Scripted Pipeline:

    node {
      stage ('STAGE NAME') {
        withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']) {
          sh '//code block'
        }
      }
    }
    

    or for Declarative Pipeline:

    pipeline {
      agent {
        label 'master'
      }
    
      stages {
        stage ('STAGE NAME') {
          steps {
            withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']) {  
              sh '''
                //code block
              '''
            }
          }
        }
    

    I hope this helps. I also struggled a lot to find a solution for this.

提交回复
热议问题