Ici, on utilise la variable GitLab CI_COMMIT_SHORT_SHA : est un identifiant court du commit, idéal pour versionner automatiquement un artefact ou une image Docker
CI_COMMIT_SHORT_SHA
Mais il y en a plein d’autres selon nos besoins :
CI_COMMIT_SHA
4a7f2b93cdab12983f7c51f1...
4a7f2b93
CI_COMMIT_REF_NAME
main
feature-x
v1.0
CI_COMMIT_BRANCH
CI_COMMIT_TAG
CI_COMMIT_MESSAGE
stages: - test hello-world: stage: test script: - echo "Coucou de GitLab CI/CD" - echo "commit: $CI_COMMIT_SHORT_SHA" - uname -a - ls -la
stages: - build - test default: image: maven:3.9-eclipse-temurin-17 cache: key: "maven-cache" paths: - .m2/repository/ policy: pull-push maven-build: stage: build script: - mvn -B -ntp clean compile artifacts: paths: - target/ expire_in: 1h maven-test: stage: test script: - mvn -B -ntp test artifacts: when: always reports: junit: target/surefire-reports/*.xml paths: - target/surefire-reports/ expire_in: 1h
stages: - lint - test default: image: maven:3.9-eclipse-temurin-17 cache: key: "maven-cache" paths: [ .m2/repository/ ] policy: pull-push lint-code: stage: lint script: - mvn -B -ntp checkstyle:check spotless:check maven-test: stage: test script: - mvn -B -ntp test artifacts: when: always reports: junit: target/surefire-reports/*.xml
stages: - build - docker maven-build: stage: build image: maven:3.9-eclipse-temurin-17 script: - mvn -B -ntp clean package -DskipTests artifacts: paths: - target/ expire_in: 1h docker-build: stage: docker image: docker:latest services: - docker:dind variables: DOCKER_DRIVER: overlay2 before_script: - echo "$CI_JOB_TOKEN" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY script: - docker build -t $CI_REGISTRY_IMAGE:latest . - docker push $CI_REGISTRY_IMAGE:latest
stages: [build, run] # Ces jobs exigent un runner local Windows taggé: shell, windows maven-build: stage: build tags: - shell - windows image: maven:3.9-eclipse-temurin-17 script: - mvn -B -ntp clean package -DskipTests artifacts: paths: [ target/ ] expire_in: 1 week run-local: stage: run tags: - shell - windows when: manual script: - echo "Lancement local du JAR" - java -jar target/*.jar