From d42ec4df2c93faf3730290c2a60971a92cd62fbc Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaev Date: Tue, 11 Jun 2019 10:58:25 +0200 Subject: [PATCH 1/3] Add pipeline based on Jenkins shared library Signed-off-by: Dmitry Nikolaev --- .tarignore | 7 +++ Jenkinsfile | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 .tarignore create mode 100644 Jenkinsfile diff --git a/.tarignore b/.tarignore new file mode 100644 index 0000000..2088d86 --- /dev/null +++ b/.tarignore @@ -0,0 +1,7 @@ +.* +*.js.map +dco-signoffs +Jenkinsfile +sonar-project.properties +webClient/node_modules +nodeServer/node_modules diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..cb96c97 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,128 @@ +#!groovy + +/** + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + + +PLUGIN_NAME = "sample-angular-app" +PLUGIN_ID = 'org.zowe.zlux.sample-angular-app' + +GITHUB_SSH_KEY = "zlux-jenkins" // This is required for git+ssh npm dependencies + + +node("zlux-agent") { + + def lib = library("jenkins-library").org.zowe.jenkins_shared_library + def pipeline = lib.pipelines.generic.GenericPipeline.new(this) + pipeline.admins.add("dnikolaev", "sgrady") + + def baseBranch = env.CHANGE_TARGET? env.CHANGE_TARGET: env.BRANCH_NAME + // A workaround to disable default checkout + (plugin_scm, scm) = [scm, null] + + def zoweManifestURL = \ + "https://raw.githubusercontent.com/zowe/zowe-install-packaging" + + "/${baseBranch}/manifest.json.template" + def zoweManifestText = httpRequest(url: zoweManifestURL).content.replace("{BUILD_NUMBER}", "-") + + pipeline.setup( + packageName: PLUGIN_ID, + version: readJSON(text: zoweManifestText)["version"], + github: [ + email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL, + usernamePasswordCredential: lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL + ], + artifactory: [ + url: lib.Constants.DEFAULT_ARTIFACTORY_URL, + usernamePasswordCredential : lib.Constants.DEFAULT_ARTIFACTORY_ROBOT_CREDENTIAL + ], + pax: [ + sshHost: lib.Constants.DEFAULT_PAX_PACKAGING_SSH_HOST, + sshPort: lib.Constants.DEFAULT_PAX_PACKAGING_SSH_PORT, + sshCredential: lib.Constants.DEFAULT_PAX_PACKAGING_SSH_CREDENTIAL, + remoteWorkspace: lib.Constants.DEFAULT_PAX_PACKAGING_REMOTE_WORKSPACE, + ], + ) + + pipeline.createStage( + name: 'Checkout', + stage: { + dir(PLUGIN_NAME) { + checkout plugin_scm + } + pipeline.github.cloneRepository( + repository: "zowe/zlux-app-manager", branch: baseBranch, folder: "zlux-app-manager" + ) + pipeline.github.cloneRepository( + repository: "zowe/zlux-platform", branch: baseBranch, folder: "zlux-platform" + ) + } + ) + + pipeline.build( + operation: { + sshagent (credentials: [GITHUB_SSH_KEY]) { + sh "cd zlux-app-manager/virtual-desktop && npm ci" + sh \ + """ + export MVD_DESKTOP_DIR=${env.WORKSPACE}/zlux-app-manager/virtual-desktop + packages=\$(find ${PLUGIN_NAME} -name package.json | { grep -v node_modules || true; }) + for package in \$packages + do + sh -c "cd `dirname \$package` && npm ci && npm run build" + done + """ + } + } + ) + + pipeline.test( + name: "Unit tests", + junit : "unit-tests-report.xml", + allowMissingJunit: true, + operation: { + sh \ + """ + packages=\$(find ${PLUGIN_NAME} -name package.json | { grep -v node_modules || true; }) + for package in \$packages + do + sh -c "cd `dirname \$package` && npm run test" + done + """ + } + ) + + // pipeline.sonarScan( + // scannerTool: lib.Constants.DEFAULT_SONARQUBE_SCANNER_TOOL, + // scannerServer: lib.Constants.DEFAULT_SONARQUBE_SERVER + // ) + + // NB: jenkins-shared-library doesn't process `.ext.ext` properly + pipeline.packaging( + name: PLUGIN_NAME, + operation: { + sh "tar --exclude-from=${PLUGIN_NAME}/.tarignore -zcvf ${PLUGIN_NAME}.tgz ${PLUGIN_NAME}" + sh "mkdir -p .pax/ascii && tar -C .pax/ascii -xf ${PLUGIN_NAME}.tgz" + pipeline.pax.pack( + job : "pax-packaging-${PLUGIN_NAME}", + filename : "${PLUGIN_NAME}.pax", + paxOptions : '', + keepTempFolder : false + ) + sh "compress .pax/${PLUGIN_NAME}.pax && mv .pax/${PLUGIN_NAME}.pax.Z ${PLUGIN_NAME}.pxz" + } + ) + + pipeline.publish( + artifacts: ["${PLUGIN_NAME}.tgz", "${PLUGIN_NAME}.pxz"] + ) + + pipeline.end() +} From 2c87643b776571f00b3738c6350f976d566eeb5a Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaev Date: Tue, 11 Jun 2019 13:13:51 +0200 Subject: [PATCH 2/3] Update to use jenkins-library@staging Signed-off-by: Dmitry Nikolaev --- Jenkinsfile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cb96c97..3c9b232 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,14 +19,11 @@ GITHUB_SSH_KEY = "zlux-jenkins" // This is required for git+ssh npm dependencies node("zlux-agent") { - def lib = library("jenkins-library").org.zowe.jenkins_shared_library + def lib = library("jenkins-library@staging").org.zowe.jenkins_shared_library def pipeline = lib.pipelines.generic.GenericPipeline.new(this) pipeline.admins.add("dnikolaev", "sgrady") def baseBranch = env.CHANGE_TARGET? env.CHANGE_TARGET: env.BRANCH_NAME - // A workaround to disable default checkout - (plugin_scm, scm) = [scm, null] - def zoweManifestURL = \ "https://raw.githubusercontent.com/zowe/zowe-install-packaging" + "/${baseBranch}/manifest.json.template" @@ -49,13 +46,14 @@ node("zlux-agent") { sshCredential: lib.Constants.DEFAULT_PAX_PACKAGING_SSH_CREDENTIAL, remoteWorkspace: lib.Constants.DEFAULT_PAX_PACKAGING_REMOTE_WORKSPACE, ], + skipCheckout: true ) pipeline.createStage( name: 'Checkout', stage: { dir(PLUGIN_NAME) { - checkout plugin_scm + checkout scm } pipeline.github.cloneRepository( repository: "zowe/zlux-app-manager", branch: baseBranch, folder: "zlux-app-manager" @@ -108,20 +106,20 @@ node("zlux-agent") { pipeline.packaging( name: PLUGIN_NAME, operation: { - sh "tar --exclude-from=${PLUGIN_NAME}/.tarignore -zcvf ${PLUGIN_NAME}.tgz ${PLUGIN_NAME}" - sh "mkdir -p .pax/ascii && tar -C .pax/ascii -xf ${PLUGIN_NAME}.tgz" + sh "tar --exclude-from=${PLUGIN_NAME}/.tarignore -zcvf ${PLUGIN_NAME}.tar.gz ${PLUGIN_NAME}" + sh "mkdir -p .pax/ascii && tar -C .pax/ascii -xf ${PLUGIN_NAME}.tar.gz" pipeline.pax.pack( job : "pax-packaging-${PLUGIN_NAME}", - filename : "${PLUGIN_NAME}.pax", + filename : "${PLUGIN_NAME}.pax.Z", paxOptions : '', - keepTempFolder : false + keepTempFolder : false, + compress : true ) - sh "compress .pax/${PLUGIN_NAME}.pax && mv .pax/${PLUGIN_NAME}.pax.Z ${PLUGIN_NAME}.pxz" } ) pipeline.publish( - artifacts: ["${PLUGIN_NAME}.tgz", "${PLUGIN_NAME}.pxz"] + artifacts: ["${PLUGIN_NAME}.tar.gz", ".pax/${PLUGIN_NAME}.pax.Z"] ) pipeline.end() From db48af58de2ee2fcc170c49b7125358c7af7a2ce Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaev Date: Wed, 12 Jun 2019 09:10:00 +0200 Subject: [PATCH 3/3] Update to use jenkins-library@master Signed-off-by: Dmitry Nikolaev --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3c9b232..e9ba592 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,7 @@ GITHUB_SSH_KEY = "zlux-jenkins" // This is required for git+ssh npm dependencies node("zlux-agent") { - def lib = library("jenkins-library@staging").org.zowe.jenkins_shared_library + def lib = library("jenkins-library").org.zowe.jenkins_shared_library def pipeline = lib.pipelines.generic.GenericPipeline.new(this) pipeline.admins.add("dnikolaev", "sgrady")