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

问题描述

我有 Windows 10,我想在 Jenkins 管道的 Jenkinsfile 中使用 bash for Ubuntu for windows 执行 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)Jenkinsworkspacepipelineascode] 运行 shell 脚本无法运行程序nohup"(在目录C:Program Files (x86)Jenkinsworkspacepipelineascode"中):CreateProcess error=2, Le fichier spécifié est introuvable

我尝试使用

C:WindowsSystem32ash.exe

但同样的错误...

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

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

推荐答案

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

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
  • 确保 Gitin 文件夹(即:C:Program FilesGitin)在全局搜索路径中,以便 Jenkins 找到 sh.exe
  • 使 Jenkins 可以使用 nohup,在 git-bash 中执行以下操作(相应地调整您的路径):
    • mklink "C:Program FilesGitbinohup.exe" "C:Program Filesgitusrinohup.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"
    • 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 FilesGitbinohup.exe" "C:Program Filesgitusrinohup.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 FilesGitcmdohup.exe" "C:Program Filesgitusrinohup.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"
      • mklink "C:Program FilesGitcmdohup.exe" "C:Program Filesgitusrinohup.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"

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

08-05 01:39