-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEVOPS-203 add Jenkinsfile #97
base: develoment
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
label = "${UUID.randomUUID().toString()}" | ||
BUILD_FOLDER = "/go" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you using absolute path instead of workspace subdir? |
||
docker_user = "iguaziodocker" | ||
docker_credentials = "iguazio-prod-docker-credentials" | ||
git_project = "iguazio_api_examples" | ||
git_project_user = "v3io" | ||
git_deploy_user = "iguazio-prod-git-user" | ||
git_deploy_user_token = "iguazio-prod-git-user-token" | ||
|
||
properties([pipelineTriggers([[$class: 'PeriodicFolderTrigger', interval: '2m']])]) | ||
podTemplate(label: "${git_project}-${label}", yaml: """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the yaml should be read from a file |
||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: "${git_project}-${label}" | ||
labels: | ||
jenkins/kube-default: "true" | ||
app: "jenkins" | ||
component: "agent" | ||
spec: | ||
shareProcessNamespace: true | ||
containers: | ||
- name: jnlp | ||
image: jenkinsci/jnlp-slave | ||
resources: | ||
limits: | ||
cpu: 1 | ||
memory: 2Gi | ||
requests: | ||
cpu: 1 | ||
memory: 2Gi | ||
volumeMounts: | ||
- name: go-shared | ||
mountPath: /go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mountPath value is a duplication of the BUILD_FOLDER |
||
- name: docker-cmd | ||
image: docker | ||
command: [ "/bin/sh", "-c", "--" ] | ||
args: [ "while true; do sleep 30; done;" ] | ||
volumeMounts: | ||
- name: docker-sock | ||
mountPath: /var/run | ||
- name: go-shared | ||
mountPath: /go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the mount path is duplication of the var |
||
volumes: | ||
- name: docker-sock | ||
hostPath: | ||
path: /var/run | ||
- name: go-shared | ||
emptyDir: {} | ||
""" | ||
) { | ||
node("${git_project}-${label}") { | ||
withCredentials([ | ||
usernamePassword(credentialsId: git_deploy_user, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'), | ||
string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') | ||
]) { | ||
def AUTO_TAG | ||
def TAG_VERSION | ||
|
||
stage('get tag data') { | ||
container('jnlp') { | ||
TAG_VERSION = sh( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its better to use common.shell in pipelinex library to avoid escaping errors |
||
script: "echo ${TAG_NAME} | tr -d '\\n' | egrep '^v[\\.0-9]*.*\$' | sed 's/v//'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember that you are using groovy - a full capable programming language so instead of doing stuff in shell, you can do: p.s from where TAG_NAME arrived to the env? i don't see it in params, if it is maybe you can just get the number and add the regex logic ... |
||
returnStdout: true | ||
).trim() | ||
|
||
sh "curl -v -H \"Authorization: token ${GIT_TOKEN}\" https://api.github.com/repos/${git_project_user}/${git_project}/releases/tags/v${TAG_VERSION} > ~/tag_version" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. common.shell instead of sh |
||
|
||
AUTO_TAG = sh( | ||
script: "cat ~/tag_version | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[\"body\"]'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can do all that in groovy no need sh, and then python |
||
returnStdout: true | ||
).trim() | ||
|
||
PUBLISHED_BEFORE = sh( | ||
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again probably you can do that in groovy |
||
returnStdout: true | ||
).trim() | ||
|
||
echo "$AUTO_TAG" | ||
echo "$TAG_VERSION" | ||
echo "$PUBLISHED_BEFORE" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its better to write echo env.AUTO_TAG |
||
} | ||
} | ||
|
||
if ( TAG_VERSION && PUBLISHED_BEFORE < 240 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what the 240 mean |
||
stage('prepare sources') { | ||
container('jnlp') { | ||
sh """ | ||
cd ${BUILD_FOLDER} | ||
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${git_project_user}/${git_project}.git src/github.com/v3io/${git_project} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for git clone there is a plugin that do that for you |
||
""" | ||
} | ||
} | ||
|
||
stage('build in dood') { | ||
container('docker-cmd') { | ||
sh """ | ||
cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project}/netops_demo/golang/src/github.com/v3io/demos | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of cd you can use the pipeline dir(path) { |
||
docker build . --tag netops-demo-golang:latest --tag ${docker_user}/netops-demo-golang:${TAG_VERSION} --build-arg NUCLIO_BUILD_OFFLINE=true --build-arg NUCLIO_BUILD_IMAGE_HANDLER_DIR=github.com/v3io/demos | ||
|
||
cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project}/netops_demo/py | ||
docker build . --tag netops-demo-py:latest --tag ${docker_user}/netops-demo-py:${TAG_VERSION} | ||
""" | ||
} | ||
} | ||
|
||
stage('push to hub') { | ||
container('docker-cmd') { | ||
withDockerRegistry([credentialsId: docker_credentials, url: ""]) { | ||
sh "docker push ${docker_user}/netops-demo-golang:${TAG_VERSION}" | ||
sh "docker push ${docker_user}/netops-demo-py:${TAG_VERSION}" | ||
} | ||
} | ||
} | ||
} else { | ||
stage('warning') { | ||
if (PUBLISHED_BEFORE >= 240) { | ||
echo "Tag too old, published before $PUBLISHED_BEFORE minutes." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure you want a warning that no one will see instead of failing the job |
||
} else if (AUTO_TAG.startsWith("Autorelease")) { | ||
echo "Autorelease does not trigger this job." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again .. check it in the start iand maybe fail it, although i don't understand something in the logic, i guess i need some explanations |
||
} else { | ||
echo "${TAG_VERSION} is not release tag." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \n in eof is missing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can write: UUID.randomUUID().toString()
also the variable name is in correct as its label_suffix
but i think you should have a var label = "${git_project}-${label_suffix}" - as you do this twice in the code