GitHub 动作:如何在步骤中使用矩阵值
GitHub Actions: How to use matrix value inside a step
我在 GitHub 操作中有一个简单的管道。我正在尝试在其中构建 Docker 图像并将其发布到 Docker Hub。我还想为不同的平台(阅读:操作系统)构建图像,因此我使用 strategy.matrix
。这是目前的样子:
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
env:
platform: ${{ matrix.platforms }}
with:
context: ./${platform}/
push: true
tags: oscarotero/lume:1.3.0-${platform} # TODO: Parameterize version once this is finally working
strategy:
matrix:
platforms:
- alpine
- debian
on:
push:
branches:
- main
这是 currently failing because it doesn't recognize platform
when running the Build and push
step. I have a similar one,它适用于这种方法。
在GitHub Actions 方面有更多知识的人可以在这里提供一些线索吗?我能想到的是 docker/build-push-action@v2
不支持那个,但在那种情况下,我该如何解决这个问题?
删除环境变量并使用matrix
值直接解决了问题:
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.platform }}/
push: true
tags: oscarotero/lume:1.3.0-${{ matrix.platform }}
strategy:
matrix:
platform:
- alpine
- debian
我在 GitHub 操作中有一个简单的管道。我正在尝试在其中构建 Docker 图像并将其发布到 Docker Hub。我还想为不同的平台(阅读:操作系统)构建图像,因此我使用 strategy.matrix
。这是目前的样子:
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
env:
platform: ${{ matrix.platforms }}
with:
context: ./${platform}/
push: true
tags: oscarotero/lume:1.3.0-${platform} # TODO: Parameterize version once this is finally working
strategy:
matrix:
platforms:
- alpine
- debian
on:
push:
branches:
- main
这是 currently failing because it doesn't recognize platform
when running the Build and push
step. I have a similar one,它适用于这种方法。
在GitHub Actions 方面有更多知识的人可以在这里提供一些线索吗?我能想到的是 docker/build-push-action@v2
不支持那个,但在那种情况下,我该如何解决这个问题?
删除环境变量并使用matrix
值直接解决了问题:
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.platform }}/
push: true
tags: oscarotero/lume:1.3.0-${{ matrix.platform }}
strategy:
matrix:
platform:
- alpine
- debian