$ docker run -d --name jenkins-ci -p 8080:8080 jenkins/jenkins:lts
http:///your-ip-addr:8080
$ docker exec -i jenkins-ci cat /var/jenkins_home/secrets/initialAdminPassword
b5102c8d9fa245dbb0b8da03f504d3a5
Follow the guided steps to finish the configuration. Save the username and password securely for future use.
$ docker pull sonatype/nexus3
Using default tag: latest
latest: Pulling from sonatype/nexus3
cb3c77f9bdd8: Pull complete
fd8daf2668d1: Pull complete
fd1ff82b00e8: Pull complete
2a05f7b573af: Pull complete
Digest: sha256:6570855dfbc3eb094fe5cbbacec87aa8b91d16394dab627177e1deeebb5ac8ee
Status: Downloaded newer image for sonatype/nexus3:latest
docker.io/sonatype/nexus3:latest
$ docker run -d --name nexus_repo -p 8081:8081 sonatype/nexus3
$ docker logs nexus_repo -f
Started Sonatype Nexus OSS 3.20.1-01
http://your-ip-addr:8081
$ docker exec -i nexus_repo cat /nexus-data/admin.password
502ace93-5450-4f0d-97d2-9b3b3a88d149
And that's it. Your Sonatype Nexus Repository is ready to use. The next step is to create a new repository.
maven-nexus-repo
, which you are going to use throughout this guide.
With this, we are through with the setup part of Sonatype Nexus Repository. Let us move to Jenkins to setup Sonatype Nexus Repository there.
Alternatively, you can also install the Maven binary directly to your container on the /var/jenkins_home
directory.
pipeline {
agent {
label "master"
}
tools {
maven "Maven"
}
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "you-ip-addr-here:8081"
NEXUS_REPOSITORY = "maven-nexus-repo"
NEXUS_CREDENTIAL_ID = "nexus-user-credentials"
}
stages {
stage("Clone code from VCS") {
steps {
script {
git 'https://github.com/javaee/cargotracker.git';
}
}
}
stage("Maven Build") {
steps {
script {
sh "mvn package -DskipTests=true"
}
}
}
stage("Publish to Nexus Repository Manager") {
steps {
script {
pom = readMavenPom file: "pom.xml";
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: pom.version,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
}
}
}
}
nexus2
or nexus3
. In our case, it is latest version of nexus3
.https
or http
.nexus-user-credentials
.https://github.com/javaee/cargotracker
Build
our project. Go to the JenkinsNexus project job page and click Build Now. As this is your first build, it is going to take some time, so sit tight.Originally published on AppFleet