Skip to content

Instantly share code, notes, and snippets.

@mikybars
Last active February 8, 2022 10:05
Show Gist options
  • Save mikybars/44188417a9dce653817b660959955811 to your computer and use it in GitHub Desktop.
Save mikybars/44188417a9dce653817b660959955811 to your computer and use it in GitHub Desktop.
Maven & GitLab CI setup to deploy to a Nexus server
variables:
NEXUS_URL: XXX
NEXUS_USER: XXX
NEXUS_PWD: XXX
SNAPSHOT_DEPLOYMENT_REPOSITORY: ${NEXUS_URL}/repository/maven-snapshots/
RELEASE_DEPLOYMENT_REPOSITORY: ${NEXUS_URL}/repository/maven-releases/
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode --errors --fail-at-end --show-version"
MAVEN_CLI_POST_OPTS: "-Dnexus.url=${NEXUS_URL} -Dmaven.repo.local=.m2"
deploy:
stage: deploy
image: maven:3.5.3-alpine
script:
# source:jar attach source and javadoc artifacts
- mvn $MAVEN_CLI_OPTS source:jar deploy -Dnexus_user=${NEXUS_USER} -Dnexus_pwd=${NEXUS_PWD} -DsnapshotDeploymentRepository=$SNAPSHOT_DEPLOYMENT_REPOSITORY -DreleaseDeploymentRepository=$RELEASE_DEPLOYMENT_REPOSITORY -DskipTests ${MAVEN_CLI_POST_OPTS}
only:
- master
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus-snapshots</id>
<username>${nexus_user}</username>
<password>${nexus_pwd}</password>
</server>
<server>
<id>nexus-releases</id>
<username>${nexus_user}</username>
<password>${nexus_pwd}</password>
</server>
</servers>
</settings>
<project>
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>${nexus.url}/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment