Jenkins doesn't recognize sh command?

I have a lot of problems trying to get Jenkinsfile to work. I tried to run this test script:

#!/usr/bin/env groovy
node {
    stage('Build') {
        echo 'Building....'
        // Create virtualenv
        sh 'echo "hi"'
    }
    stage('Test') {
        echo 'Building....'
    }
    stage('Deploy') {
        echo 'Deploying....'
    }
}

But I keep getting this error when trying to build:

Warning: JENKINS-41339 probably bogus PATH=/usr/lib64/ccache:/usr/lib64/ccache:$PATH; perhaps you meant to usePATH+EXTRA=/something/bin’?
[test-job-jenkinsfile-pipeline] Running shell script
nohup: failed to run command `sh': No such file or directory

I have updated all the pipeline plugins to the latest version and still encounter this error. Any help?

+14
source share
6 answers

So it seems the reason is that the global property was PATHcausing the problem. Going to Manage JenkinsConfigure Systemand deleting the global property PATHsolved my problem. See JENKINS-41339 .

+14
source

, $ PATH Jenkins - PATH, , , Freestyle Jenkins.

, $ PATH, $ PATH, :

PATH=/opt/blah/bin:$PATH

/opt/blah/bin , $PATH. , $PATH : /opt/blah/bin: /usr/local/bin: /usr/sbin: /bin (, , )

Jenkins Freestyle. Jenkins - $ PATH . , /opt/blah/bin:$PATH - , , $ PATH!

, , , Jenkins (1) (": Jenkins- 41339, , "), , (2) PATH, , $ PATH, . Jenkins-> .

  • PATH+EXTRA EXTRA .

  • PATH. , , PATH, : PATH+EXTRA=/opt/blah/bin

  • PATH.

, - Jenkins, , , Manage Jenkins-> Configure System.

+26

, , PATH " Manage Jenkins → Configure System ", :

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

: :

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

:

pipeline {
  agent {
    label 'master'
  }

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

, . .

+11

, sh

nohup: failed to run command `sh': No such file or directory

, . Manage Jenkins -> Configure System, , Shell

empty shell path in jenkins

, , sh. , sh , Jenkins ( ).

sh powershell *. , PowerShell.

 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

* nix, Jenkins, , sh, Jenkins, , jenkins . , sh bash,

/bin/bash

* , Jenkins Windows, Shell * nix. Windows - , Cygwin.

+1

, PATH Manage Jenkins → Configure System - PATH , -, PATH .

pipeline {
agent any
environment {
  PATH = "/usr/local/bin:$PATH"
}

nohup: failed to run command sh': No such file or directory

pipeline {
agent any
environment {
  PATH = "/usr/local/bin:${env.PATH}"
}
0

-

, , :

  1. PATH=/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/bin .
0

Source: https://habr.com/ru/post/1677198/


All Articles