This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2011 from jchauncey/azure-kubernetes-jenkinsfile
Add jenkins/Jenkinsfile.azure.kubernetes
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
node(env.NODE? env.NODE : 'slave') { | ||
withCredentials([ | ||
[$class: 'UsernamePasswordMultiBinding', credentialsId: "7a3620b2-9937-4a08-9551-ca3d0e84c503", usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWORD'], | ||
[$class: 'UsernamePasswordMultiBinding', credentialsId: '3b482378-9b9a-4784-b890-940b9bf0b234', usernameVariable: 'CLIENT_ID', passwordVariable: 'CLIENT_SECRET'], | ||
[$class: 'StringBinding', credentialsId: "2b734a0f-fb1a-4c62-8022-f4804fbd5cc9", variable: "SUBSCRIPTION_ID"], | ||
[$class: 'StringBinding', credentialsId: "94b2285f-1066-4fe2-9f6d-074649a50783", variable: "TENANT_ID"], | ||
]) { | ||
timestamps { | ||
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) { | ||
|
||
stage('Prepare') { | ||
deleteDir() | ||
checkout scm | ||
} | ||
|
||
img = docker.image("quay.io/deis/go-dev:${GO_DEV_TAG}") | ||
img.inside("-u root -v /var/run/docker.sock:/var/run/docker.sock") { | ||
env.CLIENT_ID = "${CLIENT_ID}" | ||
env.CLIENT_SECRET = "${CLIENT_SECRET}" | ||
env.TENANT_ID = "${TENANT_ID}" | ||
env.SUBSCRIPTION_ID = "${SUBSCRIPTION_ID}" | ||
|
||
env.BUILD_FROM = "${BUILD_FROM}" | ||
env.REGISTRY_USERNAME = "${REGISTRY_USERNAME}" | ||
env.REGISTRY_PASSWORD = "${REGISTRY_PASSWORD}" | ||
env.BUILD_NUMBER = "${BUILD_NUMBER}" | ||
env.TAG = "${TAG}" | ||
|
||
stage('Login to azure') { | ||
sh("az login --username ${CLIENT_ID} --password ${CLIENT_SECRET} --tenant ${TENANT_ID} --service-principal") | ||
sh("az account show") | ||
tag_count = sh(returnStdout: true, script: "az acr repository show-tags --username ${REGISTRY_USERNAME} --password ${REGISTRY_PASSWORD} --name ${REGISTRY_USERNAME} --repository hyperkube | jq '.[] | match(\"${BUILD_FROM}.azure.*\") | .string' | wc -l").toString().trim() | ||
} | ||
|
||
if ("${TAG}" != "") { | ||
tag = "${TAG}" | ||
} else { | ||
tag = "${BUILD_FROM}.azure.${tag_count}" | ||
} | ||
|
||
stage('Clone azure/kubernetes and checkout') { | ||
sh("git clone https://github.com/${BUILD_REPO} /go/src/github.com/kubernetes/kubernetes") | ||
sh("cd /go/src/github.com/kubernetes/kubernetes && git checkout ${BUILD_FROM}") | ||
} | ||
|
||
stage('Build Binaries') { | ||
sh("cd /go/src/github.com/kubernetes/kubernetes && build/run.sh make cross KUBE_FASTBUILD=true ARCH=amd64") | ||
} | ||
|
||
stage('Build Image') { | ||
sh("cd /go/src/github.com/kubernetes/kubernetes/cluster/images/hyperkube && make VERSION=${tag}") | ||
} | ||
|
||
stage('Tag and Publish Image') { | ||
sh("docker login -u ${REGISTRY_USERNAME} -p ${REGISTRY_PASSWORD} ${REGISTRY_USERNAME}.azurecr.io") | ||
|
||
// We retag the gcr image from hyperkube-amd64 to just hyperkube since we can use image tags for separate architectures | ||
sh("cd /go/src/github.com/kubernetes/kubernetes && docker tag gcr.io/google-containers/hyperkube-amd64:${tag} ${REGISTRY_USERNAME}.azurecr.io/hyperkube:${tag}") | ||
sh("cd /go/src/github.com/kubernetes/kubernetes && docker push ${REGISTRY_USERNAME}.azurecr.io/hyperkube:${tag}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |