commit 4ff8b76d7c2222f0b04e5ee58102ee74c9512ce9
parent 17fde2fd295c36ca94e74f3e394780884d34ab2c
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Sun, 26 May 2024 22:56:48 +0200
doc(jenkins): add scripted pipeline examples
Diffstat:
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/docker/docker-jenkins-inbound-agent/README b/docker/docker-jenkins-inbound-agent/README
@@ -202,8 +202,8 @@ Nomad:
== Jenkins Pipeline examples ==
-The declarative pipeline examples need to ensure that the user (`-u` flag) is
-set to the user of the Docker image. Two examples:
+The pipeline examples need to ensure that the user (`-u` flag) is set to the
+user of the Docker image. Two "declarative" pipeline examples:
pipeline {
agent {
@@ -231,7 +231,7 @@ set to the user of the Docker image. Two examples:
docker {
image 'docker.io/hashicorp/vault:latest'
label 'podman'
- args '-u root'
+ args '-u root --entrypoint=""'
}
}
@@ -246,3 +246,46 @@ set to the user of the Docker image. Two examples:
}
}
+The "scripted" pipelin is similar:
+* https://www.jenkins.io/doc/book/pipeline/docker
+
+Makes sure to set the label of the node ("podman") and the proper user for the
+Docker container (-u flag). Few examples:
+
+ node('podman') {
+ stage('runInDocker') {
+ docker.image('docker.io/arm64v8/alpine:latest').inside("-u root") {
+ writeFile(file: "readme", text: "was here --in0rdr")
+ sh '''
+ echo "hello world"
+ cat readme
+ '''
+ }
+ }
+ }
+
+ node('podman') {
+ stage('runInDocker') {
+ docker.image('docker.io/hashicorp/vault:latest').inside('-u root --entrypoint=""') {
+ sh "vault version"
+ }
+ }
+ }
+
+ node('podman') {
+ stage('runInDocker') {
+ docker.image('docker.io/arm64v8/alpine:latest').withRun() { c ->
+ sh 'echo "hi there in the logs"'
+ docker.image('docker.io/hashicorp/vault:latest').inside('-u root --entrypoint=""' +
+ ' -e "VAULT_ADDR=https://vault.in0rdr.ch"') {
+ sh "echo VAULT_VERSION: `vault version`"
+ sh "printenv | grep -i vault"
+ }
+ // inspect container before the pipeline exits
+ sh "docker inspect ${c.id}"
+ }
+ }
+ }
+
+Even more examples (not necessarily docker related):
+* https://www.jenkins.io/doc/pipeline/examples