【问题标题】:Github Action needs context is not available in container.imageGitHub Action 需要上下文在 container.image 中不可用
【发布时间】:2022-08-10 16:15:35
【问题描述】:

我正在尝试参数化 jobs.myjob.container.image 字段。文档说 needs 上下文可用:

Contexts documentation

具体来说:

Workflow key Context
jobs.<job_id>.container github, needs, strategy, matrix, env, secrets, inputs

但它不起作用。我的作业输出是一个空字符串,导致错误。

  get_image:
    name: get_image
    runs-on: self-hosted
    outputs:
      image: ${{ steps.jq.image }}
    needs:
      - ...
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: jq
        id: jq
        run: |
          set -x
          export TAG=$(jq -r \'.${{ github.event.inputs.cluster }} | .tag\' data.json)
          echo \"::set-output name=image::registry.com/mycontainer:$TAG\"

  job2:
    name: job2
    runs-on: self-hosted
    needs:
      - get_image
    container:
      image: ${{ needs.get_image.outputs.image }} <--- this is an empty string
      credentials:
        ...
    steps:
        ...

我得到的错误是Error: The template is not valid. ...: Unexpected value \'\'。

文档是在骗我还是我只是读错了?

其他问题使我认为我想做的事情是不允许的。

  • 请使用调试重新运行并显示日志在第一个作业中如何设置输出

标签: github-actions


【解决方案1】:

你应该在这里使用outputs image: ${{ steps.jq.outputs.image }}。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多