aboutsummaryrefslogtreecommitdiff
path: root/Jenkinsfile
diff options
context:
space:
mode:
Diffstat (limited to 'Jenkinsfile')
-rw-r--r--Jenkinsfile74
1 files changed, 74 insertions, 0 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..4426a26
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,74 @@
+String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
+pipeline {
+ agent {
+ docker {
+ image 'quay.io/buildah/stable'
+ args '--privileged=true'
+ }
+ }
+ options { parallelsAlwaysFailFast() }
+ triggers { cron(cron_string) }
+ environment {
+ PROJECT = 'jenkins-agent-docker-cli'
+ IMAGE_NAME = "docker.io/chn2guevara/$PROJECT"
+ }
+ stages {
+ stage('Prepare') {
+ steps {
+ sh 'dnf install git -y'
+ script {
+ env.TAG_NAME = sh(
+ returnStdout: true,
+ script: 'git name-rev --name-only --tags HEAD | sed \'s/^undefined$//\'').trim()
+ }
+ }
+ }
+ stage('Manifest') {
+ steps { sh "buildah manifest create $PROJECT" }
+ }
+ stage('Build') {
+ parallel {
+ stage('arm64/v8') {
+ steps {
+ sh"""
+ buildah build --pull --platform linux/arm64/v8 --network host \
+ --tag $IMAGE_NAME:latest --manifest $PROJECT .
+ """
+ }
+ }
+ stage('amd64') {
+ steps {
+ sh"""
+ buildah build --pull --platform linux/amd64 --network host \
+ --tag $IMAGE_NAME:latest --manifest $PROJECT .
+ """
+ }
+ }
+ }
+ }
+ stage('docker.io login') {
+ when { branch 'master' }
+ steps {
+ withCredentials([string(
+ credentialsId: 'dockerhub-personal',
+ variable: 'CREDENTIALS')
+ ]) {
+ sh '''#!/bin/bash
+ IFS=" " read -r username password <<<"$CREDENTIALS"
+ buildah login \
+ --username "$username" \
+ --password-stdin <<< "$password" docker.io
+ '''
+ }
+ }
+ }
+ stage('Push latest') {
+ when { branch 'master' }
+ steps { sh "buildah manifest push --all $PROJECT docker://$IMAGE_NAME:latest" }
+ }
+ stage('Push tag') {
+ when { allOf { branch 'master'; expression { return env.TAG_NAME == '' ? false : true } } }
+ steps { sh "buildah manifest push --all $PROJECT docker://$IMAGE_NAME:$TAG_NAME" }
+ }
+ }
+}