Jenkinsfile aktualisiert

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

58
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 image') { stage('Build and Push Docker Image') {
/* This builds the actual image; synonymous to steps {
* docker build on the command line */ script {
withCredentials([usernamePassword(credentialsId: HARBOR_CREDENTIALS, usernameVariable: 'HARBOR_USERNAME',
sh 'docker build -t andreas/rsyncd:latest' passwordVariable: 'HARBOR_PASSWORD')]) {
} sh "docker login -u ${HARBOR_USERNAME} -p ${HARBOR_PASSWORD} ${HARBOR_URL}"
stage('Test image') { sh "docker build -t ${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 ;-) */ sh "docker tag ${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG} ${HARBOR_URL}/${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
app.inside { sh "docker push ${HARBOR_URL}/${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
sh 'echo "Tests passed"' }
}
}
} }
} }
post {
stage('Push image') { always {
/* Finally, we'll push the image with two tags: echo 'Pipeline finished'
* First, the incremental build number from Jenkins
* Second, the 'latest' tag.
* Pushing multiple tags is cheap, as all the layers are reused. */
docker.withRegistry('https://harbor.lan', 'jenkins-harbor') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
} }
} }
} }