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

build: Gitlab CI/CD pipeline, get common ci_settings.xml, script for building pom

parent d5739c60
No related branches found
No related tags found
1 merge request!7Gnuaffero
Pipeline #2167 failed
image: maven:3.8.6-openjdk-11
image: openjdk:11-jdk
stages:
- build
- test
variables:
MAVEN_CLI_OPTS: "-s ci_settings.xml --batch-mode"
COMMON_CONFIG_REMOTE: https://root:$CONFIG_ACCESS_TOKEN@$CI_SERVER_HOST/VIPS/vips-common-config.git
COMMON_CONFIG_LOCAL: "vips-common-config"
SETTINGS_XML: "ci_settings.xml"
POM_WITH_MODELS: "pom_with_models.xml"
MAVEN_CLI_OPTS: "-s $SETTINGS_XML --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dmaven.artifact.threads=10"
MAIN_BRANCH: "main"
RELEASE_BRANCH: "release"
cache:
paths:
- .m2/repository/
before_script:
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- echo "Get common settings"
- git clone $COMMON_CONFIG_REMOTE $COMMON_CONFIG_LOCAL
- cd $COMMON_CONFIG_LOCAL
- cp $SETTINGS_XML ../$SETTINGS_XML
- cd ..
- rm -rf $COMMON_CONFIG_LOCAL
- apt-get update -y && apt-get install -y python3
- 'python build_pom_with_models.py'
build:
stage: build
script:
- './mvnw $MAVEN_CLI_OPTS compile'
- './mvnw -f $POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS package'
tags:
- vips-java
test:
stage: test
script:
- './mvnw $MAVEN_CLI_OPTS test'
- './mvnw -f $POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS test'
tags:
- vips-java
deploy-snapshot:
stage: deploy
script:
- './mvnw -f $POM_WITH_MODELS $MAVEN_CLI_OPTS $MAVEN_OPTS deploy'
tags:
- vips-java
\ No newline at end of file
#!/usr/bin/python3
'''
Merges pom.xml and models.xml (default) into pom_with_models.xml and
runs mvn clean install -f pom_with_models.xml
Copyright (C) 2023 NIBIO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
@author Tor-Einar Skog <tor-einar.skog@nibio.no>
'''
import sys
import subprocess
from xml.dom.minidom import parse
# Default
models_xml_path = "models.xml"
merged_pom_filename = "pom_with_models.xml"
# Accept alternative models.xml file
if len(sys.argv) > 1:
models_xml_path = sys.argv[1]
# Read contents
pom_dom = parse("pom.xml")
try:
models_dom = parse(models_xml_path)
except FileNotFoundError:
print("ERROR: File %s not found." % models_xml_path)
exit(1)
# Merge the dependency elements from models.xml into pom.xml
pom_deps_element = pom_dom.getElementsByTagName("dependencies")[0]
model_dep_elements = models_dom.getElementsByTagName("dependency")
for dep in model_dep_elements:
pom_deps_element.appendChild(dep)
# Write the modified pom dom to file
pom_with_models_file = open(merged_pom_filename,"w")
pom_dom.writexml(pom_with_models_file)
pom_with_models_file.close()
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment