Jenkins管道因“无法运行程序nohup"失败而失败.在窗户上 [英] Jenkins pipeline sh fail with "cannot run program nohup" on windows

查看:1118
本文介绍了Jenkins管道因“无法运行程序nohup"失败而失败.在窗户上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows 10,我想使用bash for Windows for Windows在Jenkins管道中的Jenkinsfile中执行sh命令,但这不起作用

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

我在Jenkins管道中处于以下阶段:

I have the following stage in my Jenkins pipeline :

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

错误消息是:

[C:\ Program Files(x86)\ Jenkins \ workspace \ pipelineascode]运行shell脚本 无法运行程序"nohup"(在目录"C:\ Program Files(x86)\ Jenkins \ workspace \ pipelineascode"中):CreateProcess error = 2,说明可解释

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

我尝试使用

C:\ Windows \ System32 \ bash.exe

C:\Windows\System32\bash.exe

但有同样的错误...

but same error...

如何使用Windows 10的bash运行sh脚本?

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

推荐答案

通过快速搜索,您的错误似乎与以下问题有关:

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

主要原因似乎是Windows不支持sh步骤.例如,您可以使用bat或安装Cygwin.

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 :

  • 安装 git-bash
  • 确保Git \ bin文件夹(即:C:\Program Files\Git\bin)位于全局搜索路径中,以便Jenkins找到sh.exe
  • 使nohup可用于Jenkins,在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
    • Install git-bash
    • Ensure the Git\bin folder (i.e.: C:\Program Files\Git\bin) 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 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"

      根据您的安装,您可能必须使用以下路径:

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

      • 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 "
      • 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"

      这篇关于Jenkins管道因“无法运行程序nohup"失败而失败.在窗户上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆