Jenkins sh fail script with “cannot run nohup program” on windows

I have windows 10 and I want to execute the sh command in the Jenkins file from the Jenkins pipeline using bash for Ubuntu for windows, but it does not work

I have the following step in my Jenkins project:

stage('sh how to') {
        steps {
            sh 'ls -l'
        }
    }

Error message:

[C: \ Program Files (x86) \ Jenkins \ workspace \ pipeascode] Running the shell scriptYou cannot run the "nohup" program (in the directory "C: \ Program Files (x86) \ Jenkins \ workspace \ pipeascode"): CreateProcess error = 2, Le fichier spécifié est introuvable

I tried to change the Jenkins-> shell parameter executable with

C: \ Windows \ System32 \ bash.exe

but the same error ...

how to run sh script using windows 10 bash?

+27
5

, : JENKINS-33708

: sh Windows. bat Cygwin .

, :

  • git - bash
  • , Git\bin (..: C:\Program Files\Git\bin) , sh.exe
  • nohup , git - bash ( ):
    • mklink "C:\Program Files\ Git\ bin\nohup.exe" "C:\Program Files\ Git\usr\bin\nohup.exe"
    • mklink "C:\Program Files\ Git\ bin\msys-2.0.dll" "C:\Program Files\ Git\usr\bin\msys-2.0.dll"
    • mklink "C:\Program Files\ Git\ bin\msys-iconv-2.dll" "C:\Program Files\ Git\usr\bin\msys-iconv -2.dll"
    • mklink "C:\Program Files\ Git\ bin\msys-intl-8.dll" "C:\Program Files\ Git\usr\bin\msys-intl -8.dll"

, , :

  • mklink "C:\Program Files\ Git\ cmd\nohup.exe" "C:\Program Files\ Git\usr\bin\nohup.exe"
  • mklink "C:\Program Files\ Git\ cmd\msys-2.0.dll" "C:\Program Files\ Git\usr\bin\msys-2.0.dll"
  • mklink "C:\Program Files\ Git\ cmd\msys-iconv-2.dll" "C:\Program Files\ Git\usr\bin\msys-iconv -2.dll"
  • mklink "C:\Program Files\ Git\ cmd\msys-intl-8.dll" "C:\Program Files\ Git\usr\bin\msys-intl -8.dll"
+36

Git Windows C:\Program Files\Git\bin PATH PATH Jenkins ( sh), C:\Program Files\Git\usr\bin PATH Windows ( nohup).

+4

Git Windows 2.16.2 C:\Program Files\Git\usr\bin PATH ( C:\Program Files\Git\bin), , , sh FreeStyle, FreeStyle. . mklink . ()

+3

Switching sh to bat worked for me - I am running Jenkins on Windows. But only after I solved the problem caused by the fact that I incorrectly configured my tools (maven and JDK) in Jenkins.

+2
source

If you are running Windows, just change sh to bat. this will work as expected. Example:

pipe pipeline {agent of any Stages {stage ("compilation stage") {

        steps {
            withMaven(maven : 'apache-maven-3.6.1') {
                bat'mvn clean compile'
            }
        }
    }

}}

0
source

All Articles