如何在基于Windows的Kubernetes pod上构建的Jenkins管道中运行批处理脚本

1sbrub3j  于 2023-04-20  发布在  Jenkins
关注(0)|答案(1)|浏览(212)

下面的管道脚本正在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”)的正确语法是什么?

frebpwbc

frebpwbc1#

单独运行dirbat 'dir'会失败,但在给定路径时会成功。
例如bat 'dir c:\\'。有趣的是PowerShell的行为不同。运行powershell 'Get-ChildItem'成功

相关问题