Matrix jobs


Matrix jobs

Matrix jobs execute the same script with different inputs

Inputs are specified using environment variables

Matrix jobs are defined using parallel

The matrix keyword under parallel defines variables sets


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)