Created
December 13, 2017 18:46
-
-
Save staylorx/a3b47de948272344c441fd0d64922f3f to your computer and use it in GitHub Desktop.
Example docker image builder with Clair test for jenkins
This file contains 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
#!/usr/bin/env groovy | |
//Dockerfile including Clair check. | |
//Steve.Taylor@cu.edu DEC-2017 | |
node('docker') { | |
def docker_registry="nexus.mydomain.err:5000" | |
def clair_endpoint="https://nexus.mydomain.err:6060" | |
def image_name="uis-cam/endpoint-heartbeat" | |
def es_version="6.0.0" | |
def full_image_name = "${docker_registry}/${image_name}:${es_version}" | |
def heartbeat | |
stage('Preparation') { | |
deleteDir() | |
git 'https://stash.cu.edu/scm/mdw/docker-endpoint-heartbeat.git' | |
} | |
stage('Build Heartbeat') { | |
dir('./') { | |
heartbeat = docker.build(image_name,"--file Dockerfile .") | |
} | |
} | |
stage('Clair Test') { | |
sh 'wget -nv -O klar http://artifactory.prod.cu.edu/artifactory/ext-archive-local/optiopay/klar/1.5/klar-1.5-linux-amd64' | |
sh 'chmod u+x klar' | |
def statusCode = sh script:"CLAIR_ADDR=${clair_endpoint} ./klar ${full_image_name}", returnStatus:true | |
if (statusCode!=0) { | |
currentBuild.result = 'FAILURE' | |
error "Docker Image did not pass Clair testing." | |
} | |
} | |
stage('Push images') { | |
//credentials from the CAM DEV Jenkins | |
docker.withRegistry("https://${docker_registry}", 'registry-credential') { | |
heartbeat.push("${es_version}") | |
heartbeat.push("latest") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment