Skip to content
Snippets Groups Projects
Commit a14a95ec authored by Lene Wasskog's avatar Lene Wasskog
Browse files

[ci skip] Merge branch 'release' into main

parents 335193db f5e38a94
Branches
Tags
1 merge request!35build: New dummy version for testing the pipeline
......@@ -37,7 +37,7 @@ before_script:
- apt-get update -y && apt-get install -y python3 && apt-get install -y rsync openssh-client
- "python3 build_pom_with_models.py"
build:
build-for-staging:
stage: build
script:
- "./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS package -DskipTests"
......@@ -48,6 +48,55 @@ build:
- target/*.war
rules:
- if: $CI_COMMIT_REF_NAME == $MAIN_BRANCH
build-for-production:
stage: build
script:
# Use access token given by CI/CD variable ACCESS_TOKEN to authenticate
# This is necessary in order to push changes to git
- &authenticate
- export NEW_REPO_URL=https://root:$ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git remote set-url --push origin $NEW_REPO_URL
- git fetch origin --prune --prune-tags
# Checkout release branch
- &checkout_release
- git stash -a
- git checkout $RELEASE_BRANCH
- git reset --hard origin/$RELEASE_BRANCH
- git stash pop
# Set release version. Commit and push if tag for release version does not already exist.
- "./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DremoveSnapshot"
- "python3 build_pom_with_models.py"
- export RELEASE_VERSION=$(./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*")
- echo "New version in release '$RELEASE_VERSION'"
# If tag for new release version already exist, exit with error
- export RELEASE_TAG="v${RELEASE_VERSION}"
- echo "Release tag '$RELEASE_TAG'"
- export EXISTING_TAGS=$(git ls-remote --tags origin | cut -f 2 | grep "refs/tags/$RELEASE_TAG$")
- echo "Existing tags '$EXISTING_TAGS'"
- if [ -n "$EXISTING_TAGS" ]; then
echo "Tag $RELEASE_TAG already exists"; exit 1;
fi
# If release tag does not already exist, commit and push pom with new version
- git add pom.xml
- |
if git diff --cached --quiet -- pom.xml; then
echo "No changes to commit for pom.xml, skipping commit and push"
else
git commit -m "[ci skip] Set release version ${RELEASE_VERSION}"
git push origin $RELEASE_BRANCH
fi
# Build new war file
- echo "Build war file with version '$RELEASE_VERSION'"
- "./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS package -DskipTests"
tags:
- vips-java
artifacts:
paths:
- target/*.war
rules:
- if: $CI_COMMIT_REF_NAME == $RELEASE_BRANCH
test:
......@@ -116,7 +165,7 @@ upload-snapshot:
deploy-to-production:
stage: deploy
script:
# Authentication setup
# Authentication setup, for running commands on server
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
......@@ -133,7 +182,7 @@ deploy-to-production:
# Find name of currently deployed application. Undeploy.
- CURRENTLY_DEPLOYED=$(ssh $SERVER_USER@$SERVER_IP "$CLI_PATH/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --commands=ls\ deployment | tr ' ' '\n' | grep VIPSCore-.*war")
- echo $CURRENTLY_DEPLOYED
- ssh $SERVER_USER@$SERVER_IP "$CLI_PATH/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --command='undeploy $CURRENTLY_DEPLOYED'"
- if [ -n "$CURRENTLY_DEPLOYED" ]; then ssh $SERVER_USER@$SERVER_IP "$CLI_PATH/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --command='undeploy $CURRENTLY_DEPLOYED'"; fi
# Deploy war file using JBoss CLI and credentials given in CI/CD variables
- echo "Deploy $WAR_FILE using JBoss CLI"
- ssh $SERVER_USER@$SERVER_IP "$CLI_PATH/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --file=$TMP_PATH/deploy.cli" > deployment.log 2>&1
......@@ -157,56 +206,42 @@ upload-and-tag-release:
stage: upload
script:
# Use access token given by CI/CD variable ACCESS_TOKEN to authenticate
- &authenticate
- export NEW_REPO_URL=https://root:$ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git remote set-url --push origin $NEW_REPO_URL
- git fetch origin --prune --prune-tags
# This is necessary in order to push changes to git
- export NEW_REPO_URL=https://root:$ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git remote set-url --push origin $NEW_REPO_URL
- git fetch origin --prune --prune-tags
# Checkout release branch
- &checkout_release
- git stash -a
- git checkout $RELEASE_BRANCH
- git reset --hard origin/$RELEASE_BRANCH
- git stash pop
- git stash -a
- git checkout $RELEASE_BRANCH
- git reset --hard origin/$RELEASE_BRANCH
- git stash pop
# Set release version and deploy. Commit, tag and push.
- &release_and_tag # Change version in pom.xml - build new pom_with_models.xml
- "./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DremoveSnapshot"
- "python build_pom_with_models.py"
- export RELEASE_VERSION=$(./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*")
- echo "New version in release '$RELEASE_VERSION'"
- export RELEASE_TAG="v${RELEASE_VERSION}"
- echo "Release tag '$RELEASE_TAG'"
- export EXISTING_TAGS=$(git ls-remote --tags origin | cut -f 2 | grep "refs/tags/$RELEASE_TAG$")
- echo "Existing tags '$EXISTING_TAGS'"
- if [ -n "$EXISTING_TAGS" ]; then
echo "Tag $RELEASE_TAG already exists"; exit 1;
fi
- "./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS deploy -DskipTests"
- git add pom.xml
- git commit -m "[ci skip] Set release version ${RELEASE_VERSION}"
- git tag -a $RELEASE_TAG -m "Tag release ${RELEASE_TAG}"
- git push origin $RELEASE_TAG
- git push origin $RELEASE_BRANCH
- export RELEASE_VERSION=$(./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*")
- export RELEASE_TAG="v${RELEASE_VERSION}"
- echo "Version to deploy '$RELEASE_VERSION', will be tagged '$RELEASE_TAG'"
- "./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS deploy -DskipTests"
# NB! Wanted to use deploy:deploy-file with already built war file above, but this requires url to be specifically set
- git tag -a $RELEASE_TAG -m "Tag release ${RELEASE_TAG}"
- git push origin $RELEASE_TAG
# Checkout main branch
- &checkout_main
- git stash -a
- git checkout $MAIN_BRANCH
- git reset --hard origin/$MAIN_BRANCH
- git stash pop
- git stash -a
- git checkout $MAIN_BRANCH
- git reset --hard origin/$MAIN_BRANCH
- git stash pop
# Merge release branch, bump patch version, push commits.
- &merge_and_bump
- git merge -m "[ci skip] Merge branch '${RELEASE_BRANCH}' into ${MAIN_BRANCH}" --no-ff $RELEASE_BRANCH
# Change version in pom.xml - build new pom_with_models.xml
- "./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DbumpPatch"
- "python build_pom_with_models.py"
- export SNAPSHOT_VERSION=$(./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*")
- echo "New version in main '$SNAPSHOT_VERSION'"
- git add pom.xml
- git commit -m "[ci skip] Set snapshot version ${SNAPSHOT_VERSION}"
- git push origin $MAIN_BRANCH
- git merge -m "[ci skip] Merge branch '${RELEASE_BRANCH}' into ${MAIN_BRANCH}" --no-ff $RELEASE_BRANCH
# Change version in pom.xml - build new pom_with_models.xml
- "./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DbumpPatch"
- "python3 build_pom_with_models.py"
- export SNAPSHOT_VERSION=$(./mvnw $MAVEN_POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*")
- echo "New version in main '$SNAPSHOT_VERSION'"
- git add pom.xml
- git commit -m "[ci skip] Set snapshot version ${SNAPSHOT_VERSION}"
- git push origin $MAIN_BRANCH
tags:
- vips-java
rules:
......
......@@ -9,7 +9,7 @@
<groupId>no.nibio</groupId>
<artifactId>VIPSCore</artifactId>
<packaging>war</packaging>
<version>2.0.5-SNAPSHOT</version>
<version>9.9.4</version>
<name>VIPSCore</name>
<url>http://maven.apache.org</url>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment