-->

DEVOPSZONES

  • Recent blogs

    Jenkins does not recognize command sh | nohup: failed to run command sh No such file or directory

    Jenkins does not recognize command sh | nohup: failed to run command sh No such file or directory

    Error:

     While working on Jenkins pipeline , I came across the issue while trying to run a simple shell script. The error says "nohup: failed to run command `sh': No such file or directory". To solve that i did the following procedure. Hope this will help you. Please like and share if the tip helps you.

    Solution:

    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
              '''
            }
          }
        }



    Thanks.

    No comments