Bitbucket Pipelines报错:'chmod'未被识别,求解决方法
Bitbucket Pipelines Windows自托管Runner执行失败:问题分析与修复
错误信息
+ chmod - R +× $BITBUCKET_ CLONE DIR/* Invoke-Expression: The term 'chmod' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C: \…….. char: 40 "chmod -R +x $BITBUCKET_CLONE_DIR/** | Invoke-Expression + + CategoryInfo : ObjectNotFound: (chmod:String) [Invoke-Expression], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException, Microsoft.PowerShell.Commands.InvokeExpressionCommand
错误原因
- 系统命令不兼容:你的自托管runner是Windows系统,但脚本里使用了Linux/Unix专属的
chmod命令,PowerShell无法识别该命令。 - YAML语法错误:
- 变量名存在空格:
$BITBUCKET CLONE DIR应为$BITBUCKET_CLONE_DIR(Bitbucket官方变量无空格) chmod命令参数错误:原命令chmod -R + $BITBUCKET CLONE DIR/*缺少执行权限标识x- After-script语法不符合PowerShell规范:Linux风格的
if判断在Windows PowerShell中无法运行
- 变量名存在空格:
修复方案
1. 替换权限命令为Windows兼容方式
Windows环境下不需要chmod给.sh脚本加权限,直接通过Git Bash(Windows runner通常预装)执行脚本即可:
bash $BITBUCKET_CLONE_DIR/DA/bitbucketscript/project-init.sh
如果脚本可改为PowerShell格式,也可直接执行:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force & $BITBUCKET_CLONE_DIR/DA/bitbucketscript/project-init.ps1
2. 修正YAML语法错误
移除无效的chmod命令,修正变量名和after-script逻辑,同时注意Windows runner不需要指定Linux镜像(cypress/base:8仅对云runner生效,自托管runner用本地环境)。
修正后的完整YAML示例
definitions: steps: step: &run_on_self_hosted_runner runs-on: - self.hosted - windows - savalktest pipelines: default: - step: name: 'DA_cypress_Test Pipeline' <<: *run_on_self_hosted_runner script: # 用Git Bash执行sh脚本(Windows runner需预装Git) - bash $BITBUCKET_CLONE_DIR/DA/bitbucketscript/project-init.sh #- cd background translations #- npm install #- npm run start & #- px cypress run --browser chrome #- sleep 600 after-script: - echo "Exit status is : $BITBUCKET_EXIT_CODE" - if ($BITBUCKET_EXIT_CODE -eq 0) { $BUILD_STATUS="Pass"; exit 0 } artifacts: - DA/reports/** - DA/cypress/videos/** - DA/cypress/screenshots/**
额外说明
- 自托管Windows runner需提前配置好Cypress、Node.js等依赖环境,因为指定的Linux镜像不会在本地生效。
- 若脚本必须用Linux环境,可将自托管runner切换为Linux系统,或在Windows上启用WSL并配置runner使用WSL环境。
内容的提问来源于stack exchange,提问作者Isira Ratnayake
相关产品推荐
相关产品推荐

