Azure DevOps Pipeline脚本报错:Bash退出代码‘127’,YAML脚本失效
Hey there, let's break down why you're hitting that error and how to fix it quickly!
What's causing the error?
Exit code 127 in Bash almost always means the shell can't find the command you're trying to run. In your pipeline, you've got start in the script step—but on Ubuntu (your chosen VM image), start isn't a built-in system command. You're trying to execute the start script defined in your package.json, but you haven't used the correct syntax to tell npm to run it.
The Simple Fix
Update your script step to use npm run start instead of just start. Here's the corrected YAML configuration:
trigger: - master pool: vmImage: 'Ubuntu-16.04' steps: - task: NodeTool@0 inputs: versionSpec: '10.x' displayName: 'Install Node.js' - script: | npm run start displayName: 'npm install and build'
Why This Works
When you define custom scripts in package.json, npm acts as the manager for these scripts. To execute one, you need to use the npm run <script-name> command—this tells npm to look up the script in your package.json and run its associated commands. Just typing start directly makes Bash search for a system-level command with that name, which doesn't exist on Ubuntu, hence the 127 error.
Bonus: Add Dependency Installation (If Needed)
If your start script relies on project dependencies that aren't pre-installed in the pipeline, you should add an npm install step first to ensure all packages are set up:
- script: | npm install npm run start displayName: 'npm install and build'
内容的提问来源于stack exchange,提问作者MD. Ashfaqur Rahman Tahashin

