image: openjdk:11-jdk-slim stages: - build - test - publish - fatjar - release before_script: - echo "---------- Start CI ----------" - export GRADLE_USER_HOME=`pwd`/.gradle - chmod +x gradlew cache: paths: - .gradle/wrapper - .gradle/caches build: stage: build script: - echo "---------- build stage ----------" - ./gradlew assemble artifacts: paths: - build/libs/*.jar expire_in: 1 week test: stage: test rules: - if: $CI_COMMIT_TAG == null # don't run for git tags image: docker:latest services: - docker:dind dependencies: - build before_script: - echo "---------- BEFORE -------------" - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - echo "---------- TEST -------------" - apk update && apk add bash openjdk11 - export JAVA_HOME=/usr/lib/jvm/java-11-openjdk - docker build --pull -t "$CI_REGISTRY_IMAGE" . - docker run --privileged -dit --name provs_test -v /var/run/docker.sock:/var/run/docker.sock $CI_REGISTRY_IMAGE - docker inspect -f '{{.State.Running}}' provs_test - ./gradlew test -Dtestdockerwithoutsudo=true artifacts: when: on_failure paths: - build/reports/tests/test reports: junit: build/test-results/test/TEST-*.xml publish: stage: publish script: - ./gradlew jar - ./gradlew publish artifacts: paths: - build/libs/*.jar expire_in: 2 months fatjar: stage: fatjar rules: - if: $CI_COMMIT_TAG before_script: - echo $CI_JOB_ID # Writing FATJAR_JOB_ID variable to environment file, as variable is needed in the release stage. - echo FATJAR_JOB_ID=$CI_JOB_ID >> generate_executables.env script: - echo "---------- create fatjar ----------" - ./gradlew fatJarLatest artifacts: paths: - 'build/libs/provs.jar' reports: # To ensure we've access to this file in the next stage dotenv: generate_executables.env expire_in: 6 months release: stage: release rules: - if: $CI_COMMIT_TAG # Run this job when a git tag is created manually needs: - job: fatjar artifacts: true image: registry.gitlab.com/gitlab-org/release-cli:latest script: - echo '------------ creating a release -------------' - echo 'Fatjar Job ID:' - echo $FATJAR_JOB_ID release: name: 'Release $CI_COMMIT_TAG' description: 'Release of provs' tag_name: '$CI_COMMIT_TAG' ref: '$CI_COMMIT_TAG' assets: links: - name: provs.jar url: https://gitlab.com/domaindrivenarchitecture/provs/-/jobs/${FATJAR_JOB_ID}/artifacts/raw/build/libs/provs.jar after_script: - echo "---------- End CI ----------"