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 {
def app
stage('Clone repository') {
/* Let's make sure we have the repository cloned to our workspace */
checkout scm
pipeline {
agent any
environment {
HARBOR_CREDENTIALS = 'jenkins-harbor'
HARBOR_URL = 'https://harbor.lan'
IMAGE_NAME = 'rsyncd'
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') {
/* This builds the actual image; synonymous to
* docker build on the command line */
sh "docker build -t ${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG} ."
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') {
/* 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"'
sh "docker push ${HARBOR_URL}/${HARBOR_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
}
}
}
}
}
stage('Push image') {
/* Finally, we'll push the image with two tags:
* 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")
post {
always {
echo 'Pipeline finished'
}
}
}