Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

bash - Jenkins pipeline sh fail with "cannot run program nohup" on windows

I have windows 10 and I want to execute the sh command in the Jenkinsfile from Jenkins pipeline using bash for Ubuntu for windows, but it doesn't work

I have the following stage in my Jenkins pipeline :

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

The error message is :

[C:Program Files (x86)Jenkinsworkspacepipelineascode] Running shell script Cannot run program "nohup" (in directory "C:Program Files (x86)Jenkinsworkspacepipelineascode"): CreateProcess error=2, Le fichier spécifié est introuvable

I tried changing Jenkins parameter->shell executable with

C:WindowsSystem32ash.exe

but same error...

how to run sh script using windows 10's bash?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From a very quick search, it looks like your error is related to the following issue : JENKINS-33708

The main cause looks like the sh step is not supported on the Windows. You may use bat or install Cygwin for instance.

Nevertheless two solutions were proposed in the previous link, suggesting you to do the following steps :

  • Install git-bash
  • Ensure the Gitin folder (i.e.: C:Program FilesGitin) is in the global search path, in order for Jenkins to find sh.exe
  • Make nohup available for Jenkins, doing the following in git-bash (adapt your paths accordingly) :
    • mklink "C:Program FilesGitbin ohup.exe" "C:Program Filesgitusrin ohup.exe"
    • mklink "C:Program FilesGitbinmsys-2.0.dll" "C:Program Filesgitusrinmsys-2.0.dll"
    • mklink "C:Program FilesGitbinmsys-iconv-2.dll" "C:Program Filesgitusrinmsys-iconv-2.dll"
    • mklink "C:Program FilesGitbinmsys-intl-8.dll" "C:Program Filesgitusrinmsys-intl-8.dll"

Depending on your installation you may have to use these paths :

  • mklink "C:Program FilesGitcmd ohup.exe" "C:Program Filesgitusrin ohup.exe"
  • mklink "C:Program FilesGitcmdmsys-2.0.dll" "C:Program Filesgitusrinmsys-2.0.dll"
  • mklink "C:Program FilesGitcmdmsys-iconv-2.dll" "C:Program Filesgitusrinmsys-iconv-2.dll"
  • mklink "C:Program FilesGitcmdmsys-intl-8.dll" "C:Program Filesgitusrinmsys-intl-8.dll"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...