Argo Workflow执行PowerShell脚本报错,请求协助排查修复
修复Argo Workflows执行PowerShell脚本的Exec格式错误
错误原因
报错Exec format error是因为Argo生成的临时脚本/argo/staging/script未指定解释器,系统尝试直接执行时无法识别其格式;同时原配置中command: ["pwsh", -c]存在YAML语法错误(-c未加引号),且配置逻辑不符合Argo Script模板的执行规则。
修复方案
方案一:添加PowerShell Shebang行
在脚本开头加入#!/usr/bin/env pwsh,明确指定脚本解释器,无需额外配置command:
apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: name: powershell-002 namespace: argo-workflows spec: entrypoint: run-powershell templates: - name: run-powershell script: image: mcr.microsoft.com/powershell:latest source: | #!/usr/bin/env pwsh Write-Host "Hello, Argo! This is a PowerShell script." $date = Get-Date Write-Host "The current date and time is: $date"
方案二:正确配置Command与Args
通过command指定pwsh解释器,args指定执行临时脚本的参数:
apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: name: powershell-002 namespace: argo-workflows spec: entrypoint: run-powershell templates: - name: run-powershell script: image: mcr.microsoft.com/powershell:latest command: ["pwsh"] args: ["/argo/staging/script"] source: | Write-Host "Hello, Argo! This is a PowerShell script." $date = Get-Date Write-Host "The current date and time is: $date"
验证方法
应用修改后的Workflow配置,执行以下命令查看实时状态:
argo submit -f your-workflow.yaml --watch
若工作流成功执行,会输出PowerShell脚本中的日志内容。
内容的提问来源于stack exchange,提问作者Lion
相关产品推荐
相关产品推荐

