Skip to content

Commit ee906ec

Browse files
authored
Devops 206 refactor (#6)
* DEVOPS-206 add Jenkinsfile * DEVOPS-206 add Jenkinsfile.multi * DEVOPS-206 refactor jenkinsfile * DEVOPS-206 refactor jenkinsfile * DEVOPS-206 refactor lib class * DEVOPS-206 push latest tag * DEVOPS-206 prep creds
1 parent 64d8591 commit ee906ec

File tree

1 file changed

+20
-54
lines changed

1 file changed

+20
-54
lines changed

Diff for: Jenkinsfile

+20-54
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
label = "${UUID.randomUUID().toString()}"
22
BUILD_FOLDER = "/go"
33
expired=240
4-
quay_user = "iguazio"
5-
quay_credentials = "iguazio-prod-quay-credentials"
6-
docker_user = "iguaziodocker"
7-
docker_credentials = "iguazio-prod-docker-credentials"
8-
artifactory_user = "k8s"
9-
artifactory_url = "iguazio-prod-artifactory-url"
10-
artifactory_credentials = "iguazio-prod-artifactory-credentials"
114
git_project = "locator"
125
git_project_user = "v3io"
13-
git_deploy_user = "iguazio-prod-git-user"
146
git_deploy_user_token = "iguazio-prod-git-user-token"
7+
git_deploy_user_private_key = "iguazio-prod-git-user-private-key"
158

16-
properties([pipelineTriggers([[$class: 'PeriodicFolderTrigger', interval: '2m']])])
179
podTemplate(label: "${git_project}-${label}", yaml: """
1810
apiVersion: v1
1911
kind: Pod
@@ -57,25 +49,19 @@ spec:
5749
) {
5850
node("${git_project}-${label}") {
5951
withCredentials([
60-
usernamePassword(credentialsId: git_deploy_user, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'),
61-
string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN'),
62-
string(credentialsId: artifactory_url, variable: 'ARTIFACTORY_URL')
52+
string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN')
6353
]) {
6454
def TAG_VERSION
55+
pipelinex = library(identifier: 'pipelinex@DEVOPS-204-pipelinex', retriever: modernSCM(
56+
[$class: 'GitSCMSource',
57+
credentialsId: git_deploy_user_private_key,
58+
remote: "[email protected]:iguazio/pipelinex.git"])).com.iguazio.pipelinex
59+
multi_credentials=[pipelinex.DockerRepo.ARTIFACTORY_IGUAZIO, pipelinex.DockerRepo.DOCKER_HUB, pipelinex.DockerRepo.QUAY_IO]
6560

6661
stage('get tag data') {
6762
container('jnlp') {
68-
TAG_VERSION = sh(
69-
script: "echo ${TAG_NAME} | tr -d '\\n' | egrep '^v[\\.0-9]*.*\$' | sed 's/v//'",
70-
returnStdout: true
71-
).trim()
72-
73-
sh "curl -H \"Authorization: token ${GIT_TOKEN}\" https://api.github.com/repos/${git_project_user}/${git_project}/releases/tags/v${TAG_VERSION} > ~/tag_version"
74-
75-
PUBLISHED_BEFORE = sh(
76-
script: "tag_published_at=\$(cat ~/tag_version | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[\"published_at\"]'); SECONDS=\$(expr \$(date +%s) - \$(date -d \"\$tag_published_at\" +%s)); expr \$SECONDS / 60 + 1",
77-
returnStdout: true
78-
).trim().toInteger()
63+
TAG_VERSION = github.get_tag_version(TAG_NAME)
64+
PUBLISHED_BEFORE = github.get_tag_published_before(git_project, git_project_user, "v${TAG_VERSION}", GIT_TOKEN)
7965

8066
echo "$TAG_VERSION"
8167
echo "$PUBLISHED_BEFORE"
@@ -85,51 +71,31 @@ spec:
8571
if ( TAG_VERSION != null && TAG_VERSION.length() > 0 && PUBLISHED_BEFORE < expired ) {
8672
stage('prepare sources') {
8773
container('jnlp') {
88-
sh """
89-
cd ${BUILD_FOLDER}
90-
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${git_project_user}/${git_project}.git src/github.com/v3io/${git_project}
91-
"""
92-
}
93-
}
94-
95-
stage('build ${git_project} in dood') {
96-
container('docker-cmd') {
97-
sh """
98-
cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project}
99-
docker build . -f Dockerfile.multi --tag ${git_project}:${TAG_VERSION} --tag ${docker_user}/${git_project}:${TAG_VERSION} --tag ${docker_user}/${git_project}:latest --tag quay.io/${quay_user}/${git_project}:${TAG_VERSION} --tag quay.io/${quay_user}/${git_project}:latest --tag ${ARTIFACTORY_URL}/${artifactory_user}/${git_project}:${TAG_VERSION} --tag ${ARTIFACTORY_URL}/${artifactory_user}/${git_project}:latest
100-
"""
101-
}
102-
}
103-
104-
stage('push to hub') {
105-
container('docker-cmd') {
106-
withDockerRegistry([credentialsId: docker_credentials, url: "https://index.docker.io/v1/"]) {
107-
sh "docker push docker.io/${docker_user}/${git_project}:${TAG_VERSION};"
108-
sh "docker push docker.io/${docker_user}/${git_project}:latest;"
74+
dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") {
75+
git(changelog: false, credentialsId: git_deploy_user_private_key, poll: false, url: "[email protected]:${git_project_user}/${git_project}.git")
76+
sh("git checkout v${TAG_VERSION}")
10977
}
11078
}
11179
}
11280

113-
stage('push to quay') {
81+
stage("build ${git_project} in dood") {
11482
container('docker-cmd') {
115-
withDockerRegistry([credentialsId: quay_credentials, url: "https://quay.io/api/v1/"]) {
116-
sh "docker push quay.io/${quay_user}/${git_project}:${TAG_VERSION}"
117-
sh "docker push quay.io/${quay_user}/${git_project}:latest"
83+
dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") {
84+
sh("docker build . -f Dockerfile.multi --tag ${git_project}:${TAG_VERSION} --tag ${git_project}:latest")
11885
}
11986
}
12087
}
12188

122-
stage('push to artifactory') {
89+
stage('push') {
12390
container('docker-cmd') {
124-
withDockerRegistry([credentialsId: artifactory_credentials, url: "https://${ARTIFACTORY_URL}/api/v1/"]) {
125-
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/${git_project}:${TAG_VERSION}"
126-
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/${git_project}:latest"
127-
}
91+
dockerx.images_push_multi_registries(["${git_project}:${TAG_VERSION}", "${git_project}:latest"], multi_credentials)
12892
}
12993
}
13094

13195
stage('update release status') {
132-
sh "release_id=\$(curl -H \"Content-Type: application/json\" -H \"Authorization: token ${GIT_TOKEN}\" -X GET https://api.github.com/repos/${git_project_user}/${git_project}/releases/tags/v${TAG_VERSION} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[\"id\"]'); curl -H \"Content-Type: application/json\" -H \"Authorization: token ${GIT_TOKEN}\" -X PATCH https://api.github.com/repos/${git_project_user}/${git_project}/releases/\${release_id} -d '{\"prerelease\": false}'"
96+
container('jnlp') {
97+
github.update_release_status(git_project, git_project_user, "v${TAG_VERSION}", GIT_TOKEN)
98+
}
13399
}
134100
} else {
135101
stage('warning') {

0 commit comments

Comments
 (0)