【问题标题】:Azure DevOps AzureCLI task with scriptPath option failed to authenticate to create Azure Container Instance带有 scriptPath 选项的 Azure DevOps AzureCLI 任务无法通过身份验证来创建 Azure 容器实例
【发布时间】:2020-04-29 08:31:05
【问题描述】:

我们在 Azure DevOps 中使用 YAML 管道。

管道中的任务之一是AzureCLI,它创建了ACI container
我们在管道的前面步骤中构建和推送的图像。

当我们从外部脚本运行此任务时,它会失败并显示以下消息:
The image '***.azurecr.io/image:1.0' in container group '***' is not accessible. Please check the image and registry credential.

当我们将脚本类型更改为inlineScript 时,它可以正常工作。

以下是不起作用的表单(scriptPath)。

- task: AzureCLI@1
  displayName: 'Run tests'
  inputs:
    azureSubscription: $(AZURE_SUBSCRIPTION)
    scriptType: 'bash'
    scriptLocation: 'scriptPath'
    scriptPath: 'run_tests.sh'

这是有效的形式(inlineScript)

- task: AzureCLI@1
    displayName: 'Run tests'
    inputs:
      azureSubscription: '$(AZURE_SUBSCRIPTION)'
      scriptLocation: 'inlineScript'
      inlineScript: 'az container create -g *** --registry-login-server ***.azurecr.io --registry-username *** --registry-password *** --image image -n test --cpu 1 --memory 8 --restart-policy Never --command-line "dotnet test.dll -n testApp -c 1000"'

脚本将超过一行。 任何线索如何从外部脚本文件 (scriptLocation: 'scriptPath') 创建 azure 容器实例?

【问题讨论】:

    标签: azure azure-devops azure-cli azure-container-instances azure-container-registry


    【解决方案1】:

    我以两种方式(scriptinline)创建了容器实例。这是我的配置:

    构建定义:

    
    steps:
    - task: replacetokens@3
      inputs:
        targetFiles: 'stackoverflow/12-container-instance/create-container-instance.sh'
        encoding: 'auto'
        writeBOM: true
        actionOnMissing: 'warn'
        keepToken: false
        tokenPrefix: '#{'
        tokenSuffix: '}#'
        useLegacyPattern: false
        enableTelemetry: true
    - task: AzureCLI@2
      displayName: 'Run tests 1'
      inputs:
        azureSubscription: '$(AzureSubscription)'
        scriptType: 'bash'
        scriptLocation: 'scriptPath'
        scriptPath: 'stackoverflow/12-container-instance/create-container-instance.sh'
    
    - task: AzureCLI@2
      displayName: 'Run tests 2'
      inputs:
        azureSubscription: '$(AzureSubscription)'
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: 'az container create -g TheCodeManual --name myapp2 --image $(Image) --registry-password $(RegistryPassword) --registry-user $(RegistryUser)'
    
    

    create-container-instance.sh 文件

    az container create -g TheCodeManual --name myapp1 --image #{Image}# --registry-password #{RegistryPassword}# --registry-user #{RegistryUser}#
    

    我使用令牌替换任务不暴露源代码管理中的敏感数据。

    不过,这两种方式都适合我。

    我注意到我不使用--registry-login-server ***.azurecr.io,但我提供了图像的完整路径,如下所示:

    az container create -g MyResourceGroup --name myapp --image myAcrRegistry.azurecr.io/myimage:latest --registry-password password --registry-user userName
    

    【讨论】:

    • 感谢您的回复。多亏了这一点,我发现我们遇到了密码周围的引号问题。
    猜你喜欢
    • 2019-06-14
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多