Jenkinsfile aktualisiert

This commit is contained in:
dresi 2025-11-03 17:12:26 +01:00
parent 1c96ec0a92
commit 159c573801

50
Jenkinsfile vendored
View File

@ -1,36 +1,32 @@
node { pipeline {
def app agent any
environment {
stage('Clone repository') { HARBOR_CREDENTIALS = 'jenkins-harbor'
/* Let's make sure we have the repository cloned to our workspace */ HARBOR_URL = 'https://harbor.lan'
IMAGE_NAME = 'rsyncd'
checkout scm IMAGE_TAG = 'latest'
} }
stages {
stage('Build and Push Docker Image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: HARBOR_CREDENTIALS, usernameVariable: 'HARBOR_USERNAME',
passwordVariable: 'HARBOR_PASSWORD')]) {
sh "docker login -u ${HARBOR_USERNAME} -p ${HARBOR_PASSWORD} ${HARBOR_URL}"
stage('Build image') { sh "docker build -t ${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG} ."
/* This builds the actual image; synonymous to
* docker build on the command line */
sh 'docker build -t andreas/rsyncd:latest' sh "docker tag ${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG} ${HARBOR_URL}/${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
}
stage('Test image') { sh "docker push ${HARBOR_URL}/${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
/* Ideally, we would run a test framework against our image.
* For this example, we're using a Volkswagen-type approach ;-) */
app.inside {
sh 'echo "Tests passed"'
} }
} }
}
stage('Push image') { }
/* Finally, we'll push the image with two tags: }
* First, the incremental build number from Jenkins post {
* Second, the 'latest' tag. always {
* Pushing multiple tags is cheap, as all the layers are reused. */ echo 'Pipeline finished'
docker.withRegistry('https://harbor.lan', 'jenkins-harbor') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
} }
} }
} }