Skip to content

add needs to two step #2

add needs to two step

add needs to two step #2

name: build-and-push-two-jobs
on:
push:
paths:
- 'jenkins/**'
- 'dind-agent/**'
env:
IMAGE_OWNER: ${{ github.repository_owner }}
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
IMAGE_OWNER: ${{ env.IMAGE_OWNER }}
steps:
-
name: Prepare Outputs
run: |
echo "IMAGE_OWNER=${{ env.IMAGE_OWNER }}" >> $GITHUB_OUTPUT
build-and-push:
needs: [prepare-matrix]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- path: ./jenkins
image: ${{ needs.prepare-matrix.outputs.IMAGE_OWNER }}/jenkins-server
- path: ./dind-agent
image: ${{ needs.prepare-matrix.outputs.IMAGE_OWNER }}/jenkins-agent
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
tags: |
type=ref,event=tag
type=raw,value=head
-
name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build Image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.path }}
push: ${{ github.event_name != 'pull_request' }}
load: ${{ github.event_name == 'pull_request' }}
file: ${{ matrix.path }}/Dockerfile
tags: |
${{ steps.meta.outputs.tags }}