From 1ff722c77230ffc4595524cd574e90eb8b0a9dd1 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 28 Nov 2018 14:41:06 +0100 Subject: [PATCH 01/12] typo --- vars/runPipeline.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vars/runPipeline.groovy b/vars/runPipeline.groovy index e7d3faa19..b294204ab 100644 --- a/vars/runPipeline.groovy +++ b/vars/runPipeline.groovy @@ -13,7 +13,7 @@ void call(Map args = [:]){ pipeline { agent { label 'linux' } stages { - stage('Helo'){ + stage('Hello'){ steps { echo "Hello, I am pipeline" } @@ -25,7 +25,7 @@ void call(Map args = [:]){ pipeline { agent { label 'linux' } stages { - stage('Helo'){ + stage('Hello'){ steps { echo "Hello, I am Test pipeline" } @@ -37,7 +37,7 @@ void call(Map args = [:]){ pipeline { agent { label 'linux' } stages { - stage('Helo'){ + stage('Hello'){ steps { echo "Hello, I am pipeline" } From 0240abf30333fac8e2006b1e71737b59e523296e Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 28 Nov 2018 16:27:55 +0100 Subject: [PATCH 02/12] method to test --- vars/dummy.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vars/dummy.groovy b/vars/dummy.groovy index 86f244385..cec9d2d3f 100644 --- a/vars/dummy.groovy +++ b/vars/dummy.groovy @@ -1,5 +1,9 @@ #!/usr/bin/env groovy +def method(){ + echo "I am a method" +} + /** A sample of a step implemantetion. From 9e5e2742defd5912e1fcab3a1e9c5aa585a9ff16 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 15:12:22 +0100 Subject: [PATCH 03/12] execute every thing on inmutable agents --- Jenkinsfile | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4a9da7b9a..1bb143a1f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,7 @@ #!/usr/bin/env groovy -library identifier: 'apm@master', -changelog: false, -retriever: modernSCM( - [$class: 'GitSCMSource', - credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba', - remote: 'git@github.com:elastic/apm-pipeline-library.git']) - pipeline { - agent any + agent { label 'linux && immutable' } environment { HOME = "${env.HUDSON_HOME}" BASE_DIR="src/github.com/elastic/apm-pipeline-library" @@ -16,11 +9,10 @@ pipeline { } options { timeout(time: 1, unit: 'HOURS') - buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '2', daysToKeepStr: '30')) + buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10', daysToKeepStr: '30')) timestamps() preserveStashes() - //see https://issues.jenkins-ci.org/browse/JENKINS-11752, https://issues.jenkins-ci.org/browse/JENKINS-39536, https://issues.jenkins-ci.org/browse/JENKINS-54133 and jenkinsci/ansicolor-plugin#132 - //ansiColor('xterm') + ansiColor('xterm') disableResume() durabilityHint('PERFORMANCE_OPTIMIZED') } @@ -32,7 +24,7 @@ pipeline { Checkout the code and stash it, to use it on other stages. */ stage('Checkout') { - agent { label 'master || linux' } + agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" @@ -55,24 +47,7 @@ pipeline { } env.JOB_GIT_COMMIT = getGitCommitSha() env.JOB_GIT_URL = "${GIT_URL}" - github_enterprise_constructor() - - on_change{ - echo "build cause a change (commit or PR)" - } - - on_commit { - echo "build cause a commit" - } - - on_merge { - echo "build cause a merge" - } - - on_pull_request { - echo "build cause PR" - } } } dir("${BASE_DIR}"){ From a840d82df8cd0ab5b5c562b74ca851562c91069f Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 15:26:33 +0100 Subject: [PATCH 04/12] execute every thing on one agent --- Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1bb143a1f..b00f3349c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,6 @@ pipeline { Checkout the code and stash it, to use it on other stages. */ stage('Checkout') { - agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" @@ -70,7 +69,6 @@ pipeline { Checkout the code and stash it, to use it on other stages. */ stage('Test') { - agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" From 96a7015fcd63f7d69a4d655d6e0787d9d42cd99d Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 15:38:29 +0100 Subject: [PATCH 05/12] execute every thing on one agent --- Jenkinsfile | 117 ++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b00f3349c..8e0572df2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ #!/usr/bin/env groovy pipeline { - agent { label 'linux && immutable' } + agent none environment { HOME = "${env.HUDSON_HOME}" BASE_DIR="src/github.com/elastic/apm-pipeline-library" @@ -20,75 +20,76 @@ pipeline { string(name: 'branch_specifier', defaultValue: "", description: "the Git branch specifier to build (branchName, tagName, commitId, etc.)") } stages { - /** - Checkout the code and stash it, to use it on other stages. - */ - stage('Checkout') { + stage('Initializing'){ + agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" } - steps { - withEnvWrapper() { - dir("${BASE_DIR}"){ - script{ - if(!env?.branch_specifier){ - echo "Checkout SCM" - checkout scm - } else { - echo "Checkout ${branch_specifier}" - checkout([$class: 'GitSCM', branches: [[name: "${branch_specifier}"]], - doGenerateSubmoduleConfigurations: false, - extensions: [], - submoduleCfg: [], - userRemoteConfigs: [[credentialsId: "${JOB_GIT_CREDENTIALS}", - url: "${GIT_URL}"]]]) + stages { + /** + Checkout the code and stash it, to use it on other stages. + */ + stage('Checkout') { + steps { + withEnvWrapper() { + dir("${BASE_DIR}"){ + script{ + if(!env?.branch_specifier){ + echo "Checkout SCM" + checkout scm + } else { + echo "Checkout ${branch_specifier}" + checkout([$class: 'GitSCM', branches: [[name: "${branch_specifier}"]], + doGenerateSubmoduleConfigurations: false, + extensions: [], + submoduleCfg: [], + userRemoteConfigs: [[credentialsId: "${JOB_GIT_CREDENTIALS}", + url: "${GIT_URL}"]]]) + } + env.JOB_GIT_COMMIT = getGitCommitSha() + env.JOB_GIT_URL = "${GIT_URL}" + github_enterprise_constructor() + } + } + dir("${BASE_DIR}"){ + sh """#!/bin/bash + MVNW_VER="maven-wrapper-0.4.2" + MVNW_DIR="maven-wrapper-\${MVNW_VER}" + curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" + tar -xzf "\${MVNW_VER}.tar.gz" + mv "\${MVNW_DIR}/.mvn/" . + mv "\${MVNW_DIR}/mvnw" . + mv "\${MVNW_DIR}/mvnw.cmd" . + rm -fr "\${MVNW_DIR}" + """ } - env.JOB_GIT_COMMIT = getGitCommitSha() - env.JOB_GIT_URL = "${GIT_URL}" - github_enterprise_constructor() - } + stash allowEmpty: true, name: 'source', useDefaultExcludes: false } + } + } + /** + Checkout the code and stash it, to use it on other stages. + */ + stage('Test') { + steps { + withEnvWrapper() { + unstash 'source' dir("${BASE_DIR}"){ - sh """#!/bin/bash - MVNW_VER="maven-wrapper-0.4.2" - MVNW_DIR="maven-wrapper-\${MVNW_VER}" - curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" - tar -xzf "\${MVNW_VER}.tar.gz" - mv "\${MVNW_DIR}/.mvn/" . - mv "\${MVNW_DIR}/mvnw" . - mv "\${MVNW_DIR}/mvnw.cmd" . - rm -fr "\${MVNW_DIR}" - """ + sh './mvnw clean test --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' } - stash allowEmpty: true, name: 'source', useDefaultExcludes: false + } } - } - } - /** - Checkout the code and stash it, to use it on other stages. - */ - stage('Test') { - options { skipDefaultCheckout() } - environment { - PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" - } - steps { - withEnvWrapper() { - unstash 'source' - dir("${BASE_DIR}"){ - sh './mvnw clean test --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' + post { + always { + junit(allowEmptyResults: true, + keepLongStdio: true, + testResults: "${BASE_DIR}/target/surefire-reports/junit-report.xml,${BASE_DIR}/target/surefire-reports/TEST-*.xml") + tar(file: "surefire-reports.tgz", archive: true, dir: "surefire-reports", pathPrefix: "${BASE_DIR}/target") + } } } } - post { - always { - junit(allowEmptyResults: true, - keepLongStdio: true, - testResults: "${BASE_DIR}/target/surefire-reports/junit-report.xml,${BASE_DIR}/target/surefire-reports/TEST-*.xml") - tar(file: "surefire-reports.tgz", archive: true, dir: "surefire-reports", pathPrefix: "${BASE_DIR}/target") - } - } } } post { From 2047ff5e128efc4eacd20e5bb5cfca0dafd1c7e2 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 15:53:27 +0100 Subject: [PATCH 06/12] execute every thing on one agent --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8e0572df2..53cc9d3ba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,6 +35,7 @@ pipeline { withEnvWrapper() { dir("${BASE_DIR}"){ script{ + sh "export" if(!env?.branch_specifier){ echo "Checkout SCM" checkout scm From f33522d6b6b09ba56ed22c242a1b3e72c7d50c98 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 16:31:11 +0100 Subject: [PATCH 07/12] execute every thing on one agent --- Jenkinsfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 53cc9d3ba..f46ed7c40 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,9 +35,8 @@ pipeline { withEnvWrapper() { dir("${BASE_DIR}"){ script{ - sh "export" if(!env?.branch_specifier){ - echo "Checkout SCM" + echo "Checkout SCM ${env?.BRANCH_NAME}" checkout scm } else { echo "Checkout ${branch_specifier}" @@ -48,8 +47,6 @@ pipeline { userRemoteConfigs: [[credentialsId: "${JOB_GIT_CREDENTIALS}", url: "${GIT_URL}"]]]) } - env.JOB_GIT_COMMIT = getGitCommitSha() - env.JOB_GIT_URL = "${GIT_URL}" github_enterprise_constructor() } } From cf0849ac42358a155a0c1e969023ab4974824780 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 16:39:40 +0100 Subject: [PATCH 08/12] execute every thing on one agent --- Jenkinsfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f46ed7c40..5fc16eaa8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,10 +35,10 @@ pipeline { withEnvWrapper() { dir("${BASE_DIR}"){ script{ - if(!env?.branch_specifier){ - echo "Checkout SCM ${env?.BRANCH_NAME}" + if(env?.BRANCH_NAME){ + echo "Checkout SCM ${BRANCH_NAME}" checkout scm - } else { + } else if (env?.branch_specifier){ echo "Checkout ${branch_specifier}" checkout([$class: 'GitSCM', branches: [[name: "${branch_specifier}"]], doGenerateSubmoduleConfigurations: false, @@ -46,6 +46,8 @@ pipeline { submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${JOB_GIT_CREDENTIALS}", url: "${GIT_URL}"]]]) + } else { + error "No valid branch." } github_enterprise_constructor() } From a136b7337211583a36013b6f062371bcde7ba5e6 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 16:55:14 +0100 Subject: [PATCH 09/12] execute every thing on one agent --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5fc16eaa8..65375ed8d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,6 @@ pipeline { agent none environment { - HOME = "${env.HUDSON_HOME}" BASE_DIR="src/github.com/elastic/apm-pipeline-library" JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba" } @@ -24,7 +23,7 @@ pipeline { agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { - PATH = "${env.PATH}:${env.HUDSON_HOME}/go/bin/:${env.WORKSPACE}/bin" + PATH = "${env.PATH}:${env.WORKSPACE}/bin" } stages { /** From ebc56893a2fca972d6b25c3c8cfecfddb3db6771 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 17:43:33 +0100 Subject: [PATCH 10/12] new gitCheckout step --- src/test/groovy/DummyStepTests.groovy | 2 + src/test/groovy/GitCheckoutStepTests.groovy | 111 ++++++++++++++++++++ vars/README.md | 24 ++++- vars/gitCheckout.groovy | 43 ++++++++ vars/gitCheckout.txt | 21 ++++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/GitCheckoutStepTests.groovy create mode 100644 vars/gitCheckout.groovy create mode 100644 vars/gitCheckout.txt diff --git a/src/test/groovy/DummyStepTests.groovy b/src/test/groovy/DummyStepTests.groovy index 3c89e3b18..cb846dcaf 100644 --- a/src/test/groovy/DummyStepTests.groovy +++ b/src/test/groovy/DummyStepTests.groovy @@ -17,6 +17,8 @@ class DummyStepTests extends BasePipelineTest { helper.registerAllowedMethod("sh", [Map.class], { "OK" }) helper.registerAllowedMethod("sh", [String.class], { "OK" }) + helper.registerAllowedMethod("withEnvWrapper", [Closure.class], { closure -> closure.call() }) + helper.registerAllowedMethod("script", [Closure.class], { closure -> closure.call() }) } @Test diff --git a/src/test/groovy/GitCheckoutStepTests.groovy b/src/test/groovy/GitCheckoutStepTests.groovy new file mode 100644 index 000000000..1f955b0fd --- /dev/null +++ b/src/test/groovy/GitCheckoutStepTests.groovy @@ -0,0 +1,111 @@ +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.junit.Before; +import org.junit.Test; +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertTrue + +class GitCheckoutStepTests extends BasePipelineTest { + Map env = [:] + + @Override + @Before + void setUp() throws Exception { + super.setUp() + + env.WORKSPACE = "WS" + binding.setVariable('env', env) + + helper.registerAllowedMethod("sh", [Map.class], { "OK" }) + helper.registerAllowedMethod("sh", [String.class], { "OK" }) + helper.registerAllowedMethod("checkout", [String.class], { "OK" }) + helper.registerAllowedMethod("github_enterprise_constructor", [], { "OK" }) + helper.registerAllowedMethod("withEnvWrapper", [Closure.class], { closure -> closure.call() }) + } + + @Test + void test() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + env.BRANCH_NAME = "BRANCH" + script.scm = "SCM" + script.call() + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "echo" + }.any { call -> + callArgsToString(call).contains("Checkout SCM ${env.BRANCH_NAME}") + }) + assertJobStatusSuccess() + } + + @Test + void testBaseDir() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + env.BRANCH_NAME = "BRANCH" + script.scm = "SCM" + script.call(basedir: 'sub-folder') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "echo" + }.any { call -> + callArgsToString(call).contains("Checkout SCM ${env.BRANCH_NAME}") + }) + assertJobStatusSuccess() + } + + @Test + void testBranch() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + script.scm = "SCM" + script.call(basedir: 'sub-folder', branch: 'master', + repo: 'git@github.com:elastic/apm-pipeline-library.git', + credentialsId: 'credentials-id') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "echo" + }.any { call -> + callArgsToString(call).contains("Checkout master") + }) + assertJobStatusSuccess() + } + + @Test + void testErrorBranchIncomplete() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + script.scm = "SCM" + script.call(basedir: 'sub-folder', branch: 'master') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "error" + }.any { call -> + callArgsToString(call).contains("No valid SCM config passed.") + }) + } + + @Test + void testErrorBranchNoCredentials() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + script.scm = "SCM" + script.call(basedir: 'sub-folder', branch: 'master', + repo: 'git@github.com:elastic/apm-pipeline-library.git') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "error" + }.any { call -> + callArgsToString(call).contains("No valid SCM config passed.") + }) + } + + @Test + void testErrorBranchNoRepo() throws Exception { + def script = loadScript("vars/gitCheckout.groovy") + script.scm = "SCM" + script.call(basedir: 'sub-folder', branch: 'master', + credentialsId: 'credentials-id') + printCallStack() + assertTrue(helper.callStack.findAll { call -> + call.methodName == "error" + }.any { call -> + callArgsToString(call).contains("No valid SCM config passed.") + }) + } +} \ No newline at end of file diff --git a/vars/README.md b/vars/README.md index 864cbfacd..ed79c79ef 100644 --- a/vars/README.md +++ b/vars/README.md @@ -64,7 +64,29 @@ Get a secret from the Vault. def jsonValue = getVaultSecret('secret-name') ``` -* *secret-name*: Name of the secret on the the vault root path.## gitCreateTag +* *secret-name*: Name of the secret on the the vault root path.## gitCheckout +Perform a checkout from the SCM configuration on a folder inside the workspace, +if branch, repo, and credentialsId are defined make a checkout using those parameters. + +``` +gitCheckout() +``` + +``` +gitCheckout(basedir: 'sub-folder') +``` + +``` +gitCheckout(basedir: 'sub-folder', branch: 'master', + repo: 'git@github.com:elastic/apm-pipeline-library.git', + credentialsId: 'credentials-id') +``` + +* *basedir*: directory where checkout the sources. +* *repo*: the repository to use. +* *credentialsId*: the credentials to access to the repository. +* *branch*: the branch to checkout from the repo. +## gitCreateTag Create a git TAG named ${BUILD_TAG} and push it to the git repo. It requires to initialise the pipeline with github_enterprise_constructor() first. diff --git a/vars/gitCheckout.groovy b/vars/gitCheckout.groovy new file mode 100644 index 000000000..7c1eac065 --- /dev/null +++ b/vars/gitCheckout.groovy @@ -0,0 +1,43 @@ +#!/usr/bin/env groovy + +/** + Perform a checkout from the SCM configuration on a folder inside the workspace, + if branch, repo, and credentialsId are defined make a checkout using those parameters. + + gitCheckout() + + gitCheckout(basedir: 'sub-folder') + + gitCheckout(basedir: 'sub-folder', branch: 'master', + repo: 'git@github.com:elastic/apm-pipeline-library.git', + credentialsId: 'credentials-id') + +*/ +def call(Map params = [:]){ + def basedir = params.containsKey('basedir') ? params.basedir : "src" + def repo = params?.repo + def credentialsId = params?.credentialsId + def branch = params?.branch + + withEnvWrapper() { + dir("${basedir}"){ + if(env?.BRANCH_NAME){ + echo "Checkout SCM ${env.BRANCH_NAME}" + checkout scm + } else if (branch && branch != "" + && repo + && credentialsId){ + echo "Checkout ${branch}" + checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], + doGenerateSubmoduleConfigurations: false, + extensions: [], + submoduleCfg: [], + userRemoteConfigs: [[credentialsId: "${credentialsId}", + url: "${repo}"]]]) + } else { + error "No valid SCM config passed." + } + github_enterprise_constructor() + } + } +} diff --git a/vars/gitCheckout.txt b/vars/gitCheckout.txt new file mode 100644 index 000000000..dfaf5d406 --- /dev/null +++ b/vars/gitCheckout.txt @@ -0,0 +1,21 @@ +Perform a checkout from the SCM configuration on a folder inside the workspace, +if branch, repo, and credentialsId are defined make a checkout using those parameters. + +``` +gitCheckout() +``` + +``` +gitCheckout(basedir: 'sub-folder') +``` + +``` +gitCheckout(basedir: 'sub-folder', branch: 'master', + repo: 'git@github.com:elastic/apm-pipeline-library.git', + credentialsId: 'credentials-id') +``` + +* *basedir*: directory where checkout the sources. +* *repo*: the repository to use. +* *credentialsId*: the credentials to access to the repository. +* *branch*: the branch to checkout from the repo. From 903b7215fb093070f466b5bd8fbf70124a6ca0fc Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 17:49:30 +0100 Subject: [PATCH 11/12] use gitCheckout step --- Jenkinsfile | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 65375ed8d..30143b209 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,40 +31,25 @@ pipeline { */ stage('Checkout') { steps { - withEnvWrapper() { - dir("${BASE_DIR}"){ - script{ - if(env?.BRANCH_NAME){ - echo "Checkout SCM ${BRANCH_NAME}" - checkout scm - } else if (env?.branch_specifier){ - echo "Checkout ${branch_specifier}" - checkout([$class: 'GitSCM', branches: [[name: "${branch_specifier}"]], - doGenerateSubmoduleConfigurations: false, - extensions: [], - submoduleCfg: [], - userRemoteConfigs: [[credentialsId: "${JOB_GIT_CREDENTIALS}", - url: "${GIT_URL}"]]]) - } else { - error "No valid branch." - } - github_enterprise_constructor() - } - } - dir("${BASE_DIR}"){ - sh """#!/bin/bash - MVNW_VER="maven-wrapper-0.4.2" - MVNW_DIR="maven-wrapper-\${MVNW_VER}" - curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" - tar -xzf "\${MVNW_VER}.tar.gz" - mv "\${MVNW_DIR}/.mvn/" . - mv "\${MVNW_DIR}/mvnw" . - mv "\${MVNW_DIR}/mvnw.cmd" . - rm -fr "\${MVNW_DIR}" - """ - } - stash allowEmpty: true, name: 'source', useDefaultExcludes: false + gitCheckout(basedir: "${BASE_DIR}", + branch: "${env?.branch_specifier}", + repo: "${env?.GIT_URL}", + credentialsId: "${JOB_GIT_CREDENTIALS}") + withEnvWrapper() { + dir("${BASE_DIR}"){ + sh """#!/bin/bash + MVNW_VER="maven-wrapper-0.4.2" + MVNW_DIR="maven-wrapper-\${MVNW_VER}" + curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" + tar -xzf "\${MVNW_VER}.tar.gz" + mv "\${MVNW_DIR}/.mvn/" . + mv "\${MVNW_DIR}/mvnw" . + mv "\${MVNW_DIR}/mvnw.cmd" . + rm -fr "\${MVNW_DIR}" + """ } + } + stash allowEmpty: true, name: 'source', useDefaultExcludes: false } } /** From 4561bf2f640084bcfcd62d647823f79a8b7de40f Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Fri, 30 Nov 2018 18:12:45 +0100 Subject: [PATCH 12/12] remove withEnvWrapper it deletes the sources --- Jenkinsfile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 30143b209..949cd22ed 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,19 +35,17 @@ pipeline { branch: "${env?.branch_specifier}", repo: "${env?.GIT_URL}", credentialsId: "${JOB_GIT_CREDENTIALS}") - withEnvWrapper() { - dir("${BASE_DIR}"){ - sh """#!/bin/bash - MVNW_VER="maven-wrapper-0.4.2" - MVNW_DIR="maven-wrapper-\${MVNW_VER}" - curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" - tar -xzf "\${MVNW_VER}.tar.gz" - mv "\${MVNW_DIR}/.mvn/" . - mv "\${MVNW_DIR}/mvnw" . - mv "\${MVNW_DIR}/mvnw.cmd" . - rm -fr "\${MVNW_DIR}" - """ - } + dir("${BASE_DIR}"){ + sh """#!/bin/bash + MVNW_VER="maven-wrapper-0.4.2" + MVNW_DIR="maven-wrapper-\${MVNW_VER}" + curl -sLO "https://github.com/takari/maven-wrapper/archive/\${MVNW_VER}.tar.gz" + tar -xzf "\${MVNW_VER}.tar.gz" + mv "\${MVNW_DIR}/.mvn/" . + mv "\${MVNW_DIR}/mvnw" . + mv "\${MVNW_DIR}/mvnw.cmd" . + rm -fr "\${MVNW_DIR}" + """ } stash allowEmpty: true, name: 'source', useDefaultExcludes: false }