diff --git a/Jenkinsfile b/Jenkinsfile index e1bf986..690a48a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,47 +1,52 @@ -def label = "node-${UUID.randomUUID().toString()}" - -podTemplate(label: label, inheritFrom: 'base', , containers: [ - containerTemplate(name: 'base', image: 'taylorchristieyardstick/build-base:node') -]) { - node(label) { - stage('Checkout Project') { - container('base') { - checkout scm - } - } - stage('Install Dependencies') { - container('base') { - sh "npm install" - sh "npm install typescript" - } - } - stage('Build the Project') { - container('base') { - sh "npx tsc" - } - } - stage('Run unit tests') { - container('base') { - sh "npm test" - } - } - stage('Login to Dockerhub') { - withCredentials([usernamePassword(credentialsId: 'DockerHubAccessYardstick', usernameVariable: 'USER', passwordVariable: 'PASS')]) { - container('base') { - sh "docker login --username ${USER} --password ${PASS}" - } - } - } - stage('Build the Docker Image') { - container('base') { - sh "make build branch=${BRANCH_NAME}" - } - } - - stage('Push the Docker Image') { - container('base') { - sh "make push branch=${BRANCH_NAME}" +pipeline { + agent { + kubernetes { + label "kaniko-${UUID.randomUUID()}" + inheritFrom 'kaniko' + containerTemplate { + name 'braid' + image 'node:8' + command 'sleep 9999' } } } -} + environment { + REPOSITORY = "yardstick/braid" + } + stages { + stage('Exec NPM commands') { + steps { + container('braid') { + checkout scm + sh 'npm install' + sh 'npm install typescript' + sh 'npx tsc' + sh 'npm test' + } + } + } + stage('Build with Kaniko') { + steps { + withCredentials([usernamePassword(credentialsId: 'DockerHubAccessYardstick', usernameVariable: 'USER', passwordVariable: 'PASS')]) { + container('kaniko') { + checkout scm + // Setup docker credentials + sh 'echo "{\\"auths\\":{\\"https://index.docker.io/v1/\\":{\\"auth\\":\\"$(printf "%s:%s" "$USER" "$PASS" | base64 | tr -d \'\n\')\\"}}}" > /kaniko/.docker/config.json' + // Execute kaniko build + sh """ + /kaniko/executor -f `pwd`/Dockerfile \ + -c `pwd` \ + --insecure=true \ + --insecure-registry=docker-registry.default:5000 \ + --cache=true \ + --cache-repo=docker-registry.default:5000/${env.REPOSITORY} \ + --destination ${env.REPOSITORY}:\$(echo ${BRANCH_NAME} | grep -Eo 'feature/([A-Za-z]+-[0-9]*)' | grep -Eo '[A-Za-z]+-[0-9]*' || \ + echo ${BRANCH_NAME} | grep -Eo '(release|hotfix)/[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+' | grep -Eo '[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+' || \ + echo ${BRANCH_NAME} | grep -Eo 'YASDEV-([[:digit:]]*)') + """ + } + } + } + } + } +} \ No newline at end of file