【问题标题】:Unable to locate executable file: 'bash' error for a simple script on Azure Devops Pipeline无法找到可执行文件:Azure Devops Pipeline 上的简单脚本出现“bash”错误
【发布时间】:2020-10-22 10:07:43
【问题描述】:

如果我运行我的 azure devops 管道,我会收到以下错误:

##[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 check the file 
mode to verify the file is executable.

我用我的自托管代理和微软托管代理都试过了,它们都有同样的错误。

这是我的管道:

trigger:
 - master

pool:
  vmImage: 'ubuntu-latest'

steps:
 - script: 
    echo Starting the build
    ./gradlew build
   displayName: 'Build

【问题讨论】:

    标签: bash azure-devops yaml azure-pipelines


    【解决方案1】:

    您需要为脚本设置 workingDirectory,如下所示:Docs

    - script: # script path or inline
      workingDirectory: #
      displayName: #
    

    例如,如果您有一个结构如下的存储库:

    RepoName
     - Folder1
       - scriptToRun
     - Folder2
    
    

    workingDirectory 的值是:

    - script: ./scriptToRun
      workingDirectory: '$(Build.SourcesDirectory)/Folder1'
      displayName: 'Build'
    

    或者您可以跳过 workingDirectory 并提供脚本的完整路径。 另请注意,此示例适用于单个存储库签出。如果您签出多个 repos,路径会有所不同。

    【讨论】:

    • 内联脚本也面临同样的错误。我该如何解决?
    • 错误是找不到 bash。并不是说找不到脚本。
    • 这没有意义,因为 Bash 预装在 Microsoft 代理上。您只需根据文档执行任务:docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/…,它应该可以工作。我假设他在控制台日志中得到了“echo Starting the build”,但在“./gradlew build”上失败了,这意味着机器上确实有 bash。我实际上有同样的问题和同样的错误信息,这是一个路径问题。
    【解决方案2】:

    我遇到了同样的问题,最初我给了我的自托管代理,一个可以访问代理池读取/管理权限的 PAT,因为这是文档中的说明,并且然后我开始收到这个错误,即使 bash 显然在我的 PATH 环境变量中。

    然后我删除了代理,将其重新添加,这次给了它一个具有完全访问权限的 PAT。

    我不再收到 bash 错误。

    【讨论】:

      【解决方案3】:

      我刚遇到这个问题,在重命名一个名为 path 的变量后,它起作用了。

      【讨论】:

        猜你喜欢
        • 2021-07-09
        • 2023-04-07
        • 2022-01-03
        • 1970-01-01
        • 2021-03-15
        • 1970-01-01
        • 1970-01-01
        • 2022-08-16
        • 1970-01-01
        相关资源
        最近更新 更多