From b483945cc0d908edaaadfead69b48721ff96bbe8 Mon Sep 17 00:00:00 2001 From: onikolskyy Date: Wed, 8 Nov 2023 18:03:43 +0100 Subject: [PATCH] a --- Jenkinsfile | 61 +++++++++++++++++++++++++++--------------------- Jenkinsfile.func | 33 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 Jenkinsfile.func diff --git a/Jenkinsfile b/Jenkinsfile index e84fb12..c9432bd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,33 +1,40 @@ -version="1.0.0" -repository="swr.eu-de.otc.t-systems.com" -tag="latest" -image="swr.eu-de.otc.t-systems.com/omnia-test/${repository}:${version}.${env.BUILD_NUMBER}" -namespace="demo" - -podTemplate(label: 'pod', cloud: 'kubernetes', serviceAccount: 'jenkins-agent-sa', - imagePullSecrets: [ - 'default-secret' - ], - containers: [ - containerTemplate( - name: 'docker', image: 'swr.eu-de.otc.t-systems.com/base-image/docker:dind', ttyEnabled: true, command: 'cat', privileged: true, - envVars: [ - secretEnvVar(key: "PASS", secretName: "docker-reg", secretKey: "docker-reg") - ] - ), - ], -) { - node('pod') { - stage('Build Docker Image') { +pipeline { + agent { + kubernetes { + yaml """\ + apiVersion: v1 + kind: Pod + metadata: + name: 'jenkins-slave' + namespace: 'your-namespace' + spec: + containers: + - name: docker + image: swr.eu-de.otc.t-systems.com/base-image/docker:dind + tty: true + imagePullPolicy: Always + imagePullSecrets: + - name: default-secret + env: + - name: PASS + valueFrom: + secretKeyRef: + name: docker-reg + key: docker-reg + """.stripIndent() + } + } + stages { + stage('Build Docker Image') { container('docker') { sh """ - docker login ${env.PASS} swr.eu-de.otc.t-systems.com - docker build -t ${image}:${tag} . - docker push ${image}:${tag} + image="swr.eu-de.otc.t-systems.com/omnia-test/test-build:latest" + docker login ${PASS} swr.eu-de.otc.t-systems.com + docker build -t ${image} . + docker push ${image} """ milestone(1) } } - } -} - + } +} \ No newline at end of file diff --git a/Jenkinsfile.func b/Jenkinsfile.func new file mode 100644 index 0000000..e84fb12 --- /dev/null +++ b/Jenkinsfile.func @@ -0,0 +1,33 @@ +version="1.0.0" +repository="swr.eu-de.otc.t-systems.com" +tag="latest" +image="swr.eu-de.otc.t-systems.com/omnia-test/${repository}:${version}.${env.BUILD_NUMBER}" +namespace="demo" + +podTemplate(label: 'pod', cloud: 'kubernetes', serviceAccount: 'jenkins-agent-sa', + imagePullSecrets: [ + 'default-secret' + ], + containers: [ + containerTemplate( + name: 'docker', image: 'swr.eu-de.otc.t-systems.com/base-image/docker:dind', ttyEnabled: true, command: 'cat', privileged: true, + envVars: [ + secretEnvVar(key: "PASS", secretName: "docker-reg", secretKey: "docker-reg") + ] + ), + ], +) { + node('pod') { + stage('Build Docker Image') { + container('docker') { + sh """ + docker login ${env.PASS} swr.eu-de.otc.t-systems.com + docker build -t ${image}:${tag} . + docker push ${image}:${tag} + """ + milestone(1) + } + } + } +} +