Matrix jobs


Matrix jobs

Matrix jobs execute the same script with different inputs

Defined using parallel

Inputs are specified using environment variables

The matrix keyword under parallel defines variables sets

Matrix variables can be used for…


Hands-On 1/

Cross-compile Go for multiple architectures

  1. Extend template to support GOOS and GOARCH:

     .build-go:
       #...
       parallel:
         matrix:
         - GOOS: linux
           GOARCH: amd64
         - GOOS: linux
           GOARCH: arm64
       script:
       - go build -o hello-${GOOS}-${GOARCH} . \
             -ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'"
    


Hands-On 2/2

  1. Update the test job:

     test:
       #...
       script:
       - ./hello-linux-amd64
    

  2. Check pipeline

See new .gitlab-ci.yml:

git checkout origin/160_gitlab_ci/150_matrix_jobs -- '*'