Nexus, Jenkins init

This commit is contained in:
moleksiienko 2025-01-13 22:54:43 +02:00
parent 53b47529be
commit d1ec84da93
3 changed files with 38 additions and 6 deletions

View file

@ -4,14 +4,16 @@ pipeline {
pollSCM('H/5 * * * *') // Watches the `dev` branch pollSCM('H/5 * * * *') // Watches the `dev` branch
} }
environment { environment {
DOCKERHUB_CREDENTIALS = credentials('nalexx6-dockerhub-pass') DOCKERHUB_CREDENTIALS = credentials('nalexxgd-docker-pass')
DOCKERHUB_USERNAME = "nalexxgd" DOCKERHUB_USERNAME = "nalexxgd"
NEXUS_URL = 'localhost:8081' NEXUS_URL = 'localhost:8081'
ARTIFACT_VERSION = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim()
} }
stages { stages {
stage('Checkout Code') { stage('Checkout Code') {
steps { steps {
git url: 'git@github.com:Nalexx06/spring-petclinic.git', credentialsId: "nalexx06_github_ssh", branch: 'dev' git url: 'https://github.com/spring-projects/spring-petclinic.git', branch: 'main'
} }
} }
@ -22,15 +24,23 @@ pipeline {
} }
stage('Upload to Nexus') { stage('Upload to Nexus') {
steps { steps {
sh './mvnw deploy -DaltDeploymentRepository=snapshots::default::${NEXUS_URL}' sh """
mvn deploy:deploy-file \\
-DgroupId=org \\
-DartifactId=petclinic \\
-Dversion=${ARTIFACT_VERSION}\\
-Dpackaging=jar \\
-Dfile=./target/spring-petclinic-${ARTIFACT_VERSION}.jar \\
-DrepositoryId=maven-snapshots \\
-Durl=http://${NEXUS_URL}/repository/maven-snapshots/ --settings settings.xml
"""
} }
} }
stage('Build Docker Image') { stage('Build Docker Image') {
steps { steps {
script { script {
def version = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() sh "docker build -t petclinic:${ARTIFACT_VERSION} ."
sh "docker build -t petclinic:${version} ." sh "docker tag petclinic:${version} ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}"
sh "docker tag petclinic:${version} ${DOCKERHUB_USERNAME}/petclinic:${version}"
sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}" sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}"
sh "docker push ${DOCKERHUB_USERNAME}/petclinic:${version}" sh "docker push ${DOCKERHUB_USERNAME}/petclinic:${version}"
} }

View file

@ -331,6 +331,14 @@
<name>Spring Milestones</name> <name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url> <url>https://repo.spring.io/milestone</url>
</pluginRepository> </pluginRepository>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>mvn-central</id>
<name>MVN central</name>
<url>https://mvnrepository.com</url>
</pluginRepository>
</pluginRepositories> </pluginRepositories>
<profiles> <profiles>

14
settings.xml Normal file
View file

@ -0,0 +1,14 @@
<settings>
<servers>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
</settings>