我有Windows 10,我想在Jenkins管道中使用bash为Ubuntu for windows执行Jen命令中的sh命令,但它不起作用
我的Jenkins管道中有以下阶段:
stage('sh how to') {
steps {
sh 'ls -l'
}
}
Run Code Online (Sandbox Code Playgroud)
错误消息是:
[C:\ Program Files(x86)\ Jenkins\workspace\pipelineascode]运行shell脚本无法运行程序"nohup"(在目录"C:\ Program Files(x86)\ Jenkins\workspace\pipelineascode"中):CreateProcess error = 2 ,Lefichierspécifiéestintrouvable
我尝试用更改Jenkins参数 - > shell可执行文件
C:\ WINDOWS\SYSTEM32\bash.exe
但同样的错误......
如何使用Windows 10的bash运行sh脚本?
在Jenkins脚本管道中,您可以像这样设置PATH env变量:
node {
git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) {
sh 'mvn -B verify'
}
}
Run Code Online (Sandbox Code Playgroud)
请注意PATH + MAVEN,如此处所述https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-withenv-code-set-environment-variables:
要设置的环境变量列表,每个变量的形式为VARIABLE = value或VARIABLE =以取消设置否则定义的变量.您也可以使用语法PATH + WHATEVER =/something来预先添加$ PATH.
但我没有在使用环境语法的声明性管道中找到如何做到这一点(如下所述:https://jenkins.io/doc/pipeline/tour/environment).
environment {
DISABLE_AUTH = 'true'
DB_ENGINE = 'sqlite'
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想更新PATH以便为我的所有阶段使用自定义工具.
我正在使用 Jenkins 声明性管道和 Docker-for-Windows 代理通过Dockerfile.
注意:不幸的是,目前不是使用基于 Linux 的 docker 守护程序的解决方案,因为我需要运行 Windows 二进制文件。
设置: Jenkins master 通过 Docker 在 Linux 16.04 上运行。詹金斯构建代理是
Docker 18.x 在尝试使用 Windows Containers 时让我头疼,所以我回滚到 17.x。当我尝试与 Jenkins 一起运行并且 nohup 不在路径上时,我仍然遇到了一些问题,但是通过将 Git 二进制文件添加到 Windows 搜索路径(另一个参考)解决了这个问题。我怀疑我当前的问题可能与此有关。
代码:我正在尝试初始化 aJenkinsfile并在其中运行一个简单的 hello-world-printout。
/詹金斯档案
pipeline {
agent none
stages {
stage('Docker Test') {
agent {
dockerfile {
filename 'Dockerfile'
label 'windocker'
}
}
steps {
println 'Hello, World!' …Run Code Online (Sandbox Code Playgroud) jenkins ×3
bash ×1
docker ×1
dockerfile ×1
jenkins-declarative-pipeline ×1
path ×1
windows-10 ×1