下面的管道脚本是从我在Kubernetes中的Jenkins实例中工作的:
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:nanoserver-1809
- name: sidecar
image: mcr.microsoft.com/dotnet/aspnet:6.0.15-windowsservercore-ltsc2019
nodeSelector:
kubernetes.io/os: windows
''') {
node(POD_LABEL) {
container(name: 'sidecar', shell: 'cmd.exe') {
echo "hello-world"
}
}
}
然而,我正在努力用批处理脚本代替echo "hello-world"
。我试着dir
"dir"
bat 'dir'
bat "dir"
bat ```dir```
典型的错误信息是
[Pipeline] { (hide)
[Pipeline] container
[Pipeline] {
[Pipeline] bat
ERROR: Process exited immediately after creation. See output below
Executing cmd.exe script inside container sidecar of pod simple-batch-44-0z85v-kb7cj-pncc6
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: Process exited immediately after creation.
执行任意批处理命令(如"dir")的正确语法是什么?
单独运行dir
或bat 'dir'
失败,但在给定路径时将成功。
例如bat 'dir c:\'
。有趣的是,PowerShell的行为有所不同。运行powershell 'Get-ChildItem'
成功