I'm trying to commit a change that I make to a build file in my build process. This job runs on MacOS as a Bash task. All sorts of other scripts and tasks are working correctly, but trying to execute these git commands is giving back a 127 error.
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo $PATH
git add $(System.DefaultWorkingDirectory)/MyFilePath/my.file
git commit -m "update file [skip ci]"
git push origin
workingDirectory: '$(Build.SourcesDirectory)'
displayName: 'Git commit'
continueOnError: true
condition: and(succeeded(), eq(variables.ChangeFile, 'true'))
What I get back is the following error(s):
========================== Starting Command Output ===========================
##[debug]which '/bin/bash'
##[debug]found: '/bin/bash'
##[debug]/bin/bash arg: /Users/runner/work/_temp/7d35e773-5913-44d8-b4fd-0d22787e7680.sh
##[debug]exec tool: /bin/bash
##[debug]arguments:
##[debug] /Users/runner/work/_temp/7d35e773-5913-44d8-b4fd-0d22787e7680.sh
/bin/bash /Users/runner/work/_temp/7d35e773-5913-44d8-b4fd-0d22787e7680.sh
/Users/runner/hostedtoolcache/NuGet/6.2.1/x64:/usr/local/lib/ruby/gems/2.7.0/bin:/usr/local/opt/ruby@2.7/bin:/usr/local/opt/pipx_bin:/Users/runner/.cargo/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Users/runner/.yarn/bin:/Users/runner/Library/Android/sdk/tools:/Users/runner/Library/Android/sdk/platform-tools:/Users/runner/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/runner/.dotnet/tools:/Users/runner/.ghcup/bin:/Users/runner/hostedtoolcache/stack/2.7.5/x64
git: 'add /Users/runner/work/1/s/MyFilePath/my.file' is not a git command. See 'git --help'.
/Users/runner/work/_temp/7d35e773-5913-44d8-b4fd-0d22787e7680.sh: line 3: git commit -m update file [skip ci]: command not found
/Users/runner/work/_temp/7d35e773-5913-44d8-b4fd-0d22787e7680.sh: line 4: git push origin: command not found
##[debug]Exit code 127 received from tool '/bin/bash'
##[debug]STDIO streams have closed for tool '/bin/bash'
##[error]Bash exited with code '127'.
Pretty vague, but here are some things I've tried:
- checkout: self
persistCredentials: true
clean: true
displayName: Checkout from git
- script: git checkout $(Build.SourceBranchName)
workingDirectory: $(Build.SourcesDirectory)
displayName: Checkout branch from git to receive commits on
failOnStderr: false
condition: and(succeeded(), eq(variables.ChangeFile, 'true'))
Any help would be most pleasant!
The reason this wasn't working is because I copied the script from Microsoft Teams. This was a big mistake. It seemed to be adding invisible characters which were causing my error messages. So the moral of the story, always paste it into an editor where you can see invisible characters first. And hopefully don't copy it from Teams in the first place!