diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Jenkinsfile | 72 |
2 files changed, 74 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e72c834 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/ssh +/repos diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0846efb --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,72 @@ +pipeline { + agent { + label 'docker' + } + triggers { + pollSCM('H/5 * * * *') // every ~5 minutes + } + + // 👇 Fill these for your setup + environment { + GIT_URL = '/var/git/git-server' + GIT_BRANCH = 'trunk' + GIT_CREDENTIALS = '' // Jenkins credentialsId (leave empty for public) + REGISTRY = 'docker.it-jaros.com' // e.g. ghcr.io/you or registry.example.com/namespace + PLATFORMS = 'linux/arm64/v8,linux/amd64' + } + + stages { + stage('Checkout') { + steps { + script { + if (env.GIT_CREDENTIALS?.trim()) { + checkout([$class: 'GitSCM', + branches: [[name: "*/${GIT_BRANCH}"]], + userRemoteConfigs: [[url: GIT_URL, credentialsId: GIT_CREDENTIALS]], + ]) + } else { + git branch: GIT_BRANCH, url: GIT_URL + } + } + } + } + + stage('Extract vars') { + steps { + script { + env.GIT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() + + // compose image name + tags + env.GROUP_ID = "com.it-jaros.git" + env.IMAGE_NAME = "${REGISTRY}/${GROUP_ID}" + echo "sha=${env.GIT_SHA}" + echo "image=${env.IMAGE_NAME}" + } + } + } + + stage('Docker buildx (multi-arch)') { + steps { + withCredentials([usernamePassword( + credentialsId: 'docker', + usernameVariable: 'DOCKER_USER', + passwordVariable: 'DOCKER_PASS' + )]) { + sh ''' + docker version + docker buildx version + docker buildx ls | grep -q multiarch || docker buildx create --name multiarch --use --bootstrap + echo "$DOCKER_PASS" | docker login $REGISTRY -u "$DOCKER_USER" --password-stdin + + DOCKER_BUILDKIT=1 docker buildx build \ + --platform ${PLATFORMS} \ + -t ${IMAGE_NAME}:${GIT_SHA} \ + -t ${IMAGE_NAME}:latest \ + --push \ + . + ''' + } + } + } + } +} |
