From 9e2918b5786cd546e4351b5d970151a197b12e01 Mon Sep 17 00:00:00 2001 From: Nicolas Berthet Date: Thu, 12 Jul 2018 10:43:56 +0800 Subject: [PATCH] Add build pipeline to publish charts --- Jenkinsfile | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0e58815 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,71 @@ +#!/usr/bin/env groovy + +@Library('nynja-common') _ + +pipeline { + environment { + SLACK_CHANNEL = "#nynja-devops-feed" + } + agent { + kubernetes(builders.simple("helm", "lachlanevenson/k8s-helm:v2.9.1")) + } + options { + skipDefaultCheckout() + buildDiscarder(logRotator(numToKeepStr: '15')) + } + stages { + stage('Checkout') { + steps { + container('helm') { + script { + def vars = checkout scm + vars.each { k,v -> env.setProperty(k, v) } + } + } + } + } + stage('Build') { + when { not { changeRequest() } } + steps { + container('helm') { + // FIXME: this should be part of our docker image + sh 'apk add --no-cache curl' + + sh 'helm init --client-only' + + withCredentials([usernamePassword(credentialsId: 'helm-publisher', usernameVariable: 'USER', passwordVariable: 'PASS')]) { + sh """ + echo "machine nynjagroup.jfrog.io" > ~/.netrc; + echo "login $USER" >> ~/.netrc; + echo "password $PASS" >> ~/.netrc; + """ + } + + script { + findFiles(glob: '*/Chart.yaml') + .each { + def (chartName) = it.path.tokenize('/') + try { + sh "helm package ${chartName}" + + findFiles(glob: "${chartName}-*.tgz").each { + sh """curl -n -T ./${it.name} "https://nynjagroup.jfrog.io/nynjagroup/helm/${it.name}" """ + } + } catch (Exception e) { + println "Failed to publish ${chartName}: ${e.message}" + } + } + } + } + } + } + } + post { + success { + slackSend channel: SLACK_CHANNEL, message: "Published updated Helm charts from `$BRANCH_NAME`", color: 'good' + } + failure { + slackSend channel: SLACK_CHANNEL, message: slackEndMsg(), color: 'danger' + } + } +} \ No newline at end of file -- GitLab