forked from cloudbees/docker
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to Jenkinsfile to allow internal releases
- Loading branch information
Showing
1 changed file
with
36 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,47 @@ | ||
/* Expected Parameters | ||
JENKINS_VERSION: the Jenkins version to release | ||
JENKINS_SHA: the sha1 | ||
INTERNAL: if true, push to an internal docker registry instead of public | ||
*/ | ||
node('dockerhub') { | ||
def internal = (INTERNAL == 'true') | ||
def dockerRegistry, dockerCredentials, warUrl | ||
if (internal) { | ||
dockerRegistry = 'https://docker.cloudbees.com' | ||
dockerCredentials = 'docker.cloudbees.com' | ||
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'nexus-internal', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD']]) { | ||
warUrl = "-u ${env.NEXUS_USERNAME}:${env.NEXUS_PASSWORD} https://nexus-internal.cloudbees.com/content/groups/mct/com/cloudbees/jenkins/main/jenkins-enterprise-war/${JENKINS_VERSION}/jenkins-enterprise-war-${JENKINS_VERSION}.war" | ||
} | ||
} else { | ||
dockerRegistry = '' | ||
dockerCredentials = 'dockerhub' | ||
warUrl = "http://jenkins-updates.cloudbees.com/download/je/${JENKINS_VERSION}/jenkins.war" | ||
} | ||
def repo = "cloudbees/jenkins-enterprise" | ||
def dockerTag = "${repo}:${JENKINS_VERSION}" | ||
def branch = "cje" | ||
|
||
stage 'Build' | ||
git url: 'https://github.com/cloudbees/docker.git', branch: branch | ||
sh "docker build --pull --no-cache --build-arg JENKINS_VERSION=${JENKINS_VERSION} --build-arg JENKINS_SHA=${JENKINS_SHA} -t ${repo}:${JENKINS_VERSION} ." | ||
// need --build-arg support | ||
//def img = docker.build("${repo}:${JENKINS_VERSION}") | ||
def img = docker.image("${repo}:${JENKINS_VERSION}") | ||
img.tag("latest") | ||
sh """ | ||
set +x | ||
docker build --pull \ | ||
--no-cache \ | ||
--build-arg "JENKINS_VERSION=${JENKINS_VERSION}" \ | ||
--build-arg "JENKINS_SHA=${JENKINS_SHA}" \ | ||
--build-arg "WAR_URL=${warUrl}" \ | ||
-t $dockerTag . | ||
""" | ||
def img = docker.image(dockerTag) | ||
if (!internal) { | ||
img.tag("latest") | ||
} | ||
|
||
stage 'Push' | ||
docker.withRegistry('', 'dockerhub') { | ||
docker.withRegistry(dockerRegistry, dockerCredentials) { | ||
img.push(); | ||
img.push('latest'); | ||
if (!internal) { | ||
img.push('latest'); | ||
} | ||
} | ||
} |