I have ensured git bash installed on the agent but still coming up with following error and i also added env variable
ERROR:
Unable to locate executable file: 'bash'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
I want to replace the token from that agent itself since that file will be available in the folder from the agent only, not in source code. and that file being generated from one of the task from azure pipeline.
that file content example:
here in above url, dev can be stage , prod etc , it need to be parameterized and use the replace token
Unable to locate executable file: 'bash'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
I can reproduce the same issue when using the Windows Self-hosted agent.
Based on your description, you have installed the git bash.
To solve this issue, you can add bash command folder in the PATH of environment variable on the agent machine.
Here are the steps:
Step1: Check if the bash.exe exists in the git bin folder.
For example:
Step2: You need to login the agent machine, and then add C:\Program Files\Git\bin to the Path of Environment Variables, then Restart the agent.
Result:
Update:
To integrate all the steps into the Pipeline, you can add the following tasks:
steps:
- task: PowerShell@2
displayName: Install Git And Config PATH ENV
inputs:
targetType: 'inline'
script: |
# Define the URL of the Git installer
$gitInstallerUrl = "https://github.com/git-for-windows/git/releases/download/v2.40.1.windows.1/Git-2.40.1-64-bit.exe"
# Define the path to save the installer
$installerPath = "$env:TEMP\Git-2.40.1-64-bit.exe"
# Download the Git installer
Invoke-WebRequest -Uri $gitInstallerUrl -OutFile $installerPath
# Run the installer silently
Start-Process -FilePath $installerPath -ArgumentList "/SILENT", "/NORESTART" -Wait
# Optionally, remove the installer after installation
Remove-Item -Path $installerPath
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
echo $env:Path
$gitpath = git --exec-path
$bashpath = $gitpath.Replace('mingw64/libexec/git-core','bin')
echo "##vso[task.setvariable variable=PATH]$bashpath;$(PATH)"
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "test"
Update2:
To directly update the file on agent machine, you can use the Bash task to run the sed command to achieve it.
Here is an example:
variables:
newvalue: dev01
steps:
- bash: 'sed -i -e "s/dev02/$(newvalue)/g" filename'
workingDirectory: 'Local Path folder where the file located(e.g. C:\Users\xx\Downloads)'
displayName: 'Bash Script'