我需要在docker build任务中用commit标签来标记docker映像,但不能在Azure管道中仅完成哈希的前7个字符

问题描述 投票:-1回答:1

需要标记具有提交的前7个字符的图像在Azure构建管道中具有价值。但无法获取,缺少语法问题。

尝试如下

  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        # Write your commands here

        echo "##vso[task.setvariable variable=dockertag] $(build.sourceversion) | cut -c-7)"
        echo "$dockertag"

dockertag在管道中的docker build任务中用作标签。

它不输出任何内容。我是否缺少任何东西,或者我们有其他替代方法吗?

azure-pipelines azure-pipelines-build-task
1个回答
0
投票

当使用##vso[task.setvariable方式在脚本中设置变量时,变量的值应适用于后续任务,但不适用于current任务。尝试这样的事情:

    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          # Write your commands here
          echo "##vso[task.setvariable variable=dockertag]$(Build.SourceVersion)|cut -c-7"
          echo $(Build.SourceVersion)
          echo done

    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          echo $(Build.SourceVersion)
          echo $(dockertag)
          echo '**********'
          echo $dockertag
          echo '**********'

结果:

enter image description here

因此,如果您的第一个bash任务可以很好地设置dockertag变量,那么您的后续步骤可以通过$(dockertag)而不是$dockertag格式使用该变量。

也应该是echo "##vso[task.setvariable variable=dockertag]$(Build.SourceVersion)|cut -c-7"

© www.soinside.com 2019 - 2024. All rights reserved.