【问题标题】:Unable to locate executable file: 'bash'找不到可执行文件:“bash”
【发布时间】:2021-02-22 03:29:37
【问题描述】:

我正在尝试在我的 azure 发布管道中运行 bash 脚本。为此,我使用了 Visual Studio 市场中的一个任务:https://marketplace.visualstudio.com/items?itemName=tsuyoshiushio.shell-exec

它将执行一个sed操作来替换一个值,如下所示:

sed -e "s/##BUILD_ID##/${RELEASE_ARTIFACTS__myapp-EBX_BUILDID}/g" "$(System.DefaultWorkingDirectory)/myapp-ebx-acc-repo/myapp-ebx-acc-current.yaml"

我正在 azure devops 服务器(自托管代理)中运行发布管道

以下是来自 azure 管道的日志:

2021-02-22T03:12:14.9277284Z ##[debug]Evaluating condition for step: 'Bash Script'
2021-02-22T03:12:14.9278320Z ##[debug]Evaluating: succeeded()
2021-02-22T03:12:14.9278426Z ##[debug]Evaluating succeeded:
2021-02-22T03:12:14.9278572Z ##[debug]=> True
2021-02-22T03:12:14.9278762Z ##[debug]Result: True
2021-02-22T03:12:14.9278943Z ##[section]Starting: Bash Script
2021-02-22T03:12:14.9436272Z ==============================================================================
2021-02-22T03:12:14.9436376Z Task         : Bash
2021-02-22T03:12:14.9436456Z Description  : Run a Bash script on macOS, Linux, or Windows
2021-02-22T03:12:14.9436521Z Version      : 3.142.2
2021-02-22T03:12:14.9436564Z Author       : Microsoft Corporation
2021-02-22T03:12:14.9436617Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613738)
2021-02-22T03:12:14.9436660Z ==============================================================================
2021-02-22T03:12:15.2650538Z ##[debug]agent.TempDirectory=C:\myapp2_agent\_work\_temp
2021-02-22T03:12:15.2652231Z ##[debug]loading inputs and endpoints
2021-02-22T03:12:15.2660837Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2021-02-22T03:12:15.2661297Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2021-02-22T03:12:15.2661699Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2021-02-22T03:12:15.2662204Z ##[debug]loading INPUT_FAILONSTDERR
2021-02-22T03:12:15.2662567Z ##[debug]loading INPUT_FILEPATH
2021-02-22T03:12:15.2662926Z ##[debug]loading INPUT_SCRIPT
2021-02-22T03:12:15.2664273Z ##[debug]loading INPUT_TARGETTYPE
2021-02-22T03:12:15.2664641Z ##[debug]loading INPUT_WORKINGDIRECTORY
2021-02-22T03:12:15.2664991Z ##[debug]loaded 8
2021-02-22T03:12:15.2665341Z ##[debug]Agent.ProxyUrl=undefined
2021-02-22T03:12:15.2665681Z ##[debug]Agent.CAInfo=undefined
2021-02-22T03:12:15.2666034Z ##[debug]Agent.ClientCert=undefined
2021-02-22T03:12:15.2666379Z ##[debug]Agent.SkipCertValidation=undefined
2021-02-22T03:12:15.2680845Z ##[debug]check path : C:\myapp2_agent\_work\_tasks\Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b\3.142.2\task.json
2021-02-22T03:12:15.2681523Z ##[debug]adding resource file: C:\myapp2_agent\_work\_tasks\Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b\3.142.2\task.json
2021-02-22T03:12:15.2682033Z ##[debug]system.culture=en-US
2021-02-22T03:12:15.2686296Z ##[debug]failOnStderr=false
2021-02-22T03:12:15.2692171Z ##[debug]workingDirectory=C:\myapp2_agent\_work\r1\a
2021-02-22T03:12:15.2692661Z ##[debug]check path : C:\myapp2_agent\_work\r1\a
2021-02-22T03:12:15.2696560Z ##[debug]targetType=inline
2021-02-22T03:12:15.2699518Z ##[debug]script=sed -e "s/##BUILD_ID##/${RELEASE_ARTIFACTS__myapp-EBX_BUILDID}/g" "C:\myapp2_agent\_work\r1\a/myapp-ebx-acc-repo/myapp-ebx-acc-current.yaml"
2021-02-22T03:12:15.2745467Z Generating script.
2021-02-22T03:12:15.2747795Z ##[debug]which 'bash'
2021-02-22T03:12:15.2828359Z ##[debug]not found
2021-02-22T03:12:15.2831165Z ##[debug]task result: Failed
2021-02-22T03:12:15.2878275Z ##[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.
2021-02-22T03:12:15.2885718Z ##[debug]Processed: ##vso[task.issue type=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.
2021-02-22T03:12:15.2900404Z ##[debug]Processed: ##vso[task.complete result=Failed;done=true;]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.
2021-02-22T03:12:15.2945778Z ##[section]Finishing: Bash Script

添加 Exec Shell 后出错

2021-02-22T08:40:02.0724451Z ==============================================================================
2021-02-22T08:40:02.0724559Z Task         : Shell Exec
2021-02-22T08:40:02.0724626Z Description  : Execute shell commands without creating a shell file
2021-02-22T08:40:02.0724687Z Version      : 0.2.0
2021-02-22T08:40:02.0724738Z Author       : Tsuyoshi Ushio
2021-02-22T08:40:02.0724781Z Help         : Replace with markdown to show in help
2021-02-22T08:40:02.0724824Z ==============================================================================
2021-02-22T08:40:02.3703799Z ##[debug]agent.workFolder=C:\myapp2_agent\_work
2021-02-22T08:40:02.3704912Z ##[debug]loading inputs and endpoints
2021-02-22T08:40:02.3705348Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2021-02-22T08:40:02.3705717Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2021-02-22T08:40:02.3706081Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2021-02-22T08:40:02.3706415Z ##[debug]loading INPUT_CODE
2021-02-22T08:40:02.3716803Z ##[debug]loaded 4
2021-02-22T08:40:02.3740815Z ##[debug]Absolute path for pathSegments: C:\myapp2_agent\externals\git\cmd/bash = C:\myapp2_agent\externals\git\cmd\bash
2021-02-22T08:40:02.3752877Z ##[debug]Absolute path for pathSegments: C:\Program Files\Common Files\Oracle\Java\javapath/bash = C:\Program Files\Common Files\Oracle\Java\javapath\bash
2021-02-22T08:40:02.3753334Z ##[debug]Absolute path for pathSegments: C:\windows\system32/bash = C:\windows\system32\bash
2021-02-22T08:40:02.3754760Z ##[debug]Absolute path for pathSegments: C:\windows/bash = C:\windows\bash
2021-02-22T08:40:02.3756901Z ##[debug]Absolute path for pathSegments: C:\windows\System32\Wbem/bash = C:\windows\System32\Wbem\bash
2021-02-22T08:40:02.3760607Z ##[debug]Absolute path for pathSegments: C:\windows\System32\WindowsPowerShell\v1.0\/bash = C:\windows\System32\WindowsPowerShell\v1.0\bash
2021-02-22T08:40:02.3763009Z ##[debug]Absolute path for pathSegments: C:\windows\System32\OpenSSH\/bash = C:\windows\System32\OpenSSH\bash
2021-02-22T08:40:02.3766217Z ##[debug]Absolute path for pathSegments: C:\Program Files\Git\cmd/bash = C:\Program Files\Git\cmd\bash
2021-02-22T08:40:02.3768040Z ##[debug]Absolute path for pathSegments: C:\Users\tsiadm\Downloads/bash = C:\Users\tsiadm\Downloads\bash
2021-02-22T08:40:02.3769821Z ##[debug]Absolute path for pathSegments: C:\Program Files\Docker/bash = C:\Program Files\Docker\bash
2021-02-22T08:40:02.3771587Z ##[debug]Absolute path for pathSegments: F:\agentutility\apache-maven-3.6.3\bin/bash = F:\agentutility\apache-maven-3.6.3\bin\bash
2021-02-22T08:40:02.3773290Z ##[debug]Absolute path for pathSegments: C:\PROGRA~1\Java\jdk-15.0.2\bin/bash = C:\PROGRA~1\Java\jdk-15.0.2\bin\bash
2021-02-22T08:40:02.3776148Z ##[debug]Absolute path for pathSegments: C:\Users\PANDES04\AppData\Local\Microsoft\WindowsApps/bash = C:\Users\ADMPANDES04\AppData\Local\Microsoft\WindowsApps\bash
2021-02-22T08:40:02.3779987Z ##[debug]check path : null
2021-02-22T08:40:02.4326569Z (node:13088) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed which: Not found bash: null
2021-02-22T08:40:02.4406217Z ##[section]Finishing: shellexec 

【问题讨论】:

    标签: azure azure-devops azure-devops-self-hosted-agent


    【解决方案1】:

    使用以下命令添加 powershell 任务解决了问题

    $path="$(System.DefaultWorkingDirectory)/myapp-ebx-acc-repo/myapp-ebx-acc-current.yaml"

    (Get-Content $path) -replace "##BUILD_ID##","$(Release.Artifacts.myapp-ebx.BuildId)" |输出文件 $path 获取内容 $path

    【讨论】:

    • 您好,感谢您的分享,您可以Accept it as an Answer,它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
    • 你好。 “Get-Content $path”到底是什么意思?看起来是多余的...
    【解决方案2】:

    如果您在 Azure DevOps 组织中安装此第三个扩展:Shell exec task without file,则此外部任务:Shell Exec 现在在 Azure 管道中可用。

    但是,您提供的日志显示您正在使用此系统预定义的Bash task,请检查您是否正在使用目标任务来运行此 bash 脚本。

    【讨论】:

    • 是的,我正在使用 3rd 方扩展来替换我的 k8s 部署清单文件中的 docker 映像标签
    • 更新了我的答案以指向外部任务:Shell Exec 供您参考。
    • 我正在使用 azure devops 服务器,但无法在我的环境中找到相同的 Shell Exec 扩展
    • 如果你已经在集合中安装了这个Shell exec task without file扩展,你可以到Collection Settings>Extensions页面找到它。然后你可以在管道中使用这个 shell exec 任务,方法是在添加新任务时使用它的名称搜索这个任务。
    • 我添加了 Shell Exec 扩展并执行但没有运气
    猜你喜欢
    • 2019-11-02
    • 2013-11-20
    • 2012-07-22
    • 2017-05-07
    • 1970-01-01
    • 2020-10-25
    • 2021-12-14
    相关资源
    最近更新 更多