You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions:如何在step步骤中使用matrix矩阵配置值

问题原因
  • GitHub Actions中,Action的with输入参数在工作流预解析阶段处理,不支持读取env字段定义的shell环境变量,你使用的${platform}是shell环境变量读取语法,仅在run字段的shell脚本执行时生效,这是变量识别失败的核心原因,和docker/build-push-action的版本无关。
  • 你此前的同类配置能正常运行,大概率是因为之前的变量应用场景是run字段下的shell命令,而非Action的with输入参数。
解决方案

不需要将matrix值中转到环境变量,直接在with字段中通过GitHub Actions内置表达式引用matrix变量即可,${{ }}包裹的变量可以在with字段中正常解析:

name: Build and Publish Docker image(s)

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Log in to Docker Hub
        uses: docker/login-action@v1
        with:
          password: ${{ secrets.DOCKERHUB_TOKEN }}
          registry: docker.io
          username: ${{ secrets.DOCKERHUB_USERNAME }}
      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: ./${{ matrix.platforms }}/
          push: true
          tags: oscarotero/lume:1.3.0-${{ matrix.platforms }} # TODO: Parameterize version once this is finally working
    strategy:
      matrix:
        platforms:
          - alpine
          - debian

on:
  push:
    branches:
      - main

如果你确实需要先将matrix值存入环境变量再使用,需要用${{ env.platform }}的表达式语法读取环境变量,而非shell的${platform}写法。

内容的提问来源于stack exchange,提问作者user4695271

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 18:27:03