Jenkins-无法识别cmd [英] Jenkins - cmd is not recognized
问题描述
环境:
- 主Linux Jenkins服务器
- 两个Windows从节点
- Windows从站正在作为服务运行
首次测试
- 我创建管道并在构建部分中使用执行Windows批处理命令"
- 在命令"框中,输入"C:\ Jenkins \ mytest.bat"
- 我选中了限制此项目的运行位置"框,并写下Windows从站的名称
- 我建立了管道,并且成功
- I create a Pipeline and use a use a "Execute Windows batch command" in the build section
- In the Command box I put "C:\Jenkins\mytest.bat"
- I checked the box "Restrict where this project can be run" and write down the name of the Windows slave
- I built the pipeline and was successful
第二次考试
-
我创建一个声明性管道,如下所示:
I create a Declarative Pipeline as follows:
pipeline {
agent { label 'SiebelWindows' }
stages {
stage('Test Bat') {
steps {
bat 'C:\\Jenkins\\mytest.bat'
//bat 'start cmd.exe /c C:\\Jenkins\\mytest.bat'
//call C:\\Jenkins\\mytest.bat
}
}
}
}
在这种情况下,错误为"cmd未被识别为内部或外部命令"的构建 FAIL
那么,为什么我可以在非声明性管道中运行.bat,而在声明性管道中运行失败?
So, why can I run the .bat with a non-declarative pipeline, but fails with a declarative pipeline?
推荐答案
当我显示"Path"和"PATH"变量时,这就是结果
When I display the "Path" and the "PATH" variables, this was the result
解决方案是重新定义PATH环境变量,像这样
The solution was redefine the PATH enviorement variable, like this
environment {
PATH = "C:\\WINDOWS\\SYSTEM32"
}
@JustAProgrammer向我询问,如果C:\ WINDOWS \ SYSTEM32在我的Windows计算机的PATH中,那是正确的,但似乎Jenkins主服务器不知道该从计算机的Windows路径.
@JustAProgrammer aske me if C:\WINDOWS\SYSTEM32 was in the PATH of my Windows machine, and that is correct, but seems like Jenkins master do not know the slave's Windows Path.
我已经解决了我的问题,但是我仍在寻找一个完整的解决方案,我需要使用所有路径设置PATH环境变量,而不仅仅是C:\ WINDOWS \ SYSTEM32
I resolve my issue, but I still looking for a complete solution, I need to set the PATH enviorement variable with ALL the path, no only C:\WINDOWS\SYSTEM32
这篇关于Jenkins-无法识别cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!