Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
.gitlab-ci.yml 3.30 KiB
image: 'maven:3.6.3-jdk-11-slim'

variables:
  PROJECT_ARTIFACT_ID: kypo-adaptive-training
  DEPLOYMENT_INFO_VERSION_FILE: VERSION.txt

stages:
  - create_tag
  - build
  - tests
  - docker_image_push

create_tag:
  stage: create_tag
  before_script:
    # ssh config
    - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh -o 'StrictHostKeyChecking no' "$SSH_HOST_CHECKING_DOMAIN"
    # git config
    - apt-get install git -y
    - git config --global user.email "$GIT_USER_EMAIL"
    - git config --global user.name "$GIT_USER_NAME"
    - git remote set-url origin "$GIT_CLONE_URL"
    - git fetch
    - git checkout master
  script:
    - export VERSION=$(grep -oP '^([^\s]*)' $DEPLOYMENT_INFO_VERSION_FILE)
    - export TAG_MESSAGE=$(grep -oP '(?<=\s)[^\s].*' $DEPLOYMENT_INFO_VERSION_FILE)
    # update project in this project
    - mvn versions:set -DnewVersion=$VERSION -DgenerateBackupPoms=false -Dproprietary-repo-url=$PROPRIETARY_REPO_URL
    - git commit -am "Update pom.xml version based on GitLab tag. Done by CI."
    # generate swagger documentation
    - mvn clean compile -DskipTests -Dswagger.skip=false -Dproprietary-repo-url=$PROPRIETARY_REPO_URL
    - git add doc-files/kypo-adaptive-training-open-api.yaml
    - git commit -m "Updated Swagger documentation generated."
    # update change log
    - LAST_TAG=$(git tag | head -1)
    - git log  --pretty=format:'%h -- %s' $LAST_TAG..HEAD --graph > CHANGELOG.md
    - git add CHANGELOG.md
    - git commit -m "CHANGELOG.md file updated with commits between the current and previous tag. Done by CI."
    # create new tag
    - git tag -a v$VERSION -m "$TAG_MESSAGE"
    - git config --global push.followTags true
    - git push
  rules:
    - if: '$CI_COMMIT_BRANCH == "master"'
      changes:
        - VERSION.txt
  artifacts:
    paths:
      - ./pom.xml
      - ./*/pom.xml
    expire_in: 1 hour
    when: on_success

build:
  stage: build
  script:
    - mvn clean install -DskipTests -Dproprietary-repo-url=$PROPRIETARY_REPO_URL
  rules:
    - if: '$CI_COMMIT_BRANCH'
  artifacts:
    paths:
      - target/$PROJECT_ARTIFACT_ID-*.jar
    expire_in: 1 hour
    when: on_success