Created
March 14, 2019 14:47
-
-
Save mrballcb/c8877b3803af53e3649bdb16f2717869 to your computer and use it in GitHub Desktop.
Jenkinsfile for building docker images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def OUR_DOCKER = "docker.example.com" | |
// Requires leading slash, no trailing slash | |
def PROJECT_URL = "/logging/logstash" | |
def pod_label = "buildpod-${env.JOB_NAME.reverse().take(35).reverse()}-${env.BUILD_NUMBER}".replace('_', '-').replace('/', '-') | |
podTemplate( | |
label: pod_label, | |
containers: [ | |
containerTemplate(name: 'docker-builder', image: "${OUR_DOCKER}/helpers/docker-builder", ttyEnabled: true, command: 'cat') | |
], | |
volumes: [ | |
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock') | |
], | |
imagePullSecrets: [ 'your_docker_pull_secret' ], | |
) { | |
node(pod_label) { | |
checkout scm | |
container('docker-builder') { | |
def push_label = sh(returnStdout: true, script: "git describe --abbrev=8 --long").trim() | |
stage('Build & Publish') { | |
docker.withRegistry("https://${OUR_DOCKER}","your_docker_push_secret") { | |
// Can't use docker-pipeline commands under Kube until JENKINS-46447 is fixed | |
// new_image.push() | |
sh "docker build --network=host -t '${OUR_DOCKER}${PROJECT_URL}:${push_label}' -f Dockerfile . " | |
sh "docker push '${OUR_DOCKER}${PROJECT_URL}:${push_label}' " | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment