Thoughtworks公司pipe_script脚本
env.SCM_URL = "git@git.haihangyun.net:root/HNA-Brightness.git" env.SCM_CREDENTIALS = "080207fb-ee29-47be-b228-66cbd8fd801a" env.BUILD_IMAGE_CORE = "brightness/core" env.BUILD_IMAGE_FRONT = "brightness/front" env.BUILD_VERSION = null env.REPO_CREDENTIALS = "registry-login" env.REPO_SNAPSHOT = "http://xa-brightness-1.chinacloudapp.cn:5002" node { stage 'CHECKOUT' git url: "${env.SCM_URL}",credentialsId: "${env.SCM_CREDENTIALS}" env.BUILD_VERSION = version() stage 'BUILD WAR' docker.image('baselibrary/gradle:jdk8').inside('-v /root/.gradle:/root/.gradle -v /usr/sbin/vault:/usr/sbin/vault -v /etc/hosts:/etc/hosts') { sh 'cd brightness-core&&gradle war -Penv=dev' } stage 'COMPASS' docker.image('baselibrary/nodejs:5').inside('-v /root/.npmrc:/root/.npmrc -v /etc/hosts:/etc/hosts') { sh 'npm install&&npm run build' } stage 'PACKAGE' sh ''' cp config/coreDockerfile Dockerfile ''' def dockerImageCore = docker.build("${env.BUILD_IMAGE_CORE}:${env.BUILD_NUMBER}") sh ''' cp config/frontendDockerfile Dockerfile ''' def dockerImageFRONT = docker.build("${env.BUILD_IMAGE_FRONT}:${env.BUILD_NUMBER}") stage 'PUBLISH' docker.withRegistry("${env.REPO_SNAPSHOT}","${env.REPO_CREDENTIALS}") { dockerImageCore.push("${env.BUILD_NUMBER}") } docker.withRegistry("${env.REPO_SNAPSHOT}","${env.REPO_CREDENTIALS}") { dockerImageFRONT.push("${env.BUILD_NUMBER}") } stage 'DEPLOY' env.RANCHER_STACK = "brightness-DEV" sh "sed -i 's#%BUILD_IMAGE_CORE%#${env.BUILD_IMAGE_CORE}:${env.BUILD_NUMBER}#g' config/docker-compose.yml" sh "sed -i 's#%BUILD_IMAGE_FRONT%#${env.BUILD_IMAGE_FRONT}:${env.BUILD_NUMBER}#g' config/docker-compose.yml" sh ''' cd config&&rancher-compose -p $RANCHER_STACK up -d -c --upgrade''' stage 'ARCHIVE' archive 'brightness-data-service/build/libs/brightness-data-service-*.jar' archive 'brightness-core/build/libs/brightness-core-*.war' archive 'dist/*' } /* node{ stage 'CHECKOUT TEST ' git url: "${env.SCM_URL_TEST}",credentialsId: "${env.SCM_CREDENTIALS}" stage "Functional Test" docker.image('baselibrary/ruby:2.5').inside('-e DOMIAN=dev -v /etc/hosts:/etc/hosts') { sh 'cucumber features --tags=@e2e DOMAIN=dev' } }*/ def version() { def matcher = readFile('brightness-core/build.gradle') =~ 'version = \'(.*)\'' matcher ? matcher[0][1] : null }
pipeline官方提供的脚本
// Run this on the master node: node { // The JDK is configured as a tool with the name 'jdk-8u77' in the Jenkins 'Global Tool Configuration' env.JAVA_HOME="${tool 'jdk-8u77'}" env.PATH="${env.JAVA_HOME}/bin:${env.PATH}" // Maven is configured as a tool with the name 'M3' in the Jenkins 'Global Tool Configuration'. def mvnHome = tool 'M3' stage 'Checkout' // Configure the credential in Jenkins,and use the credential's ID in the following step: git url: 'ssh://git@gitrepo.computas.com/fs/fs-knowledge-editor.git',credentialsId: '8dbfb6d2-2549-4c6e-9a6e-994ae8797efc' stage 'Build and tag' // Define the version of this build. // BASE_VERSION is defined as a build parameter in the UI definition of the job. // Note how Groovy code is used to format the number of the current build. def version = "${BASE_VERSION}-J2TEST-" + currentBuild.number.toString().padLeft(4,'0') // Execute the maven command as a shell command step. On Windows,a 'bat'-step would be used instead. sh "${mvnHome}/bin/mvn clean verify -f KnowledgeEditor/pom.xml -Dfs.version=${version}" // Archive the zip file for access in through the Jenkins UI,or for other uses. archive 'KnowledgeEditor/com.computas.fs.ke.products/target/products/*.zip' // Each build is tagged with an annotated tag. // There is no pipeline plugin for this (the Git Publisher plugin is not compatible),// so everything has to be implemented using shell commands. // First,we have to configure git with the mandatory user information: sh "git config user.name \"Jenkins Pipeline\"" sh "git config user.email bob@computas.com" // Next,tag this commit. def msg = "\"Automatically created tag ${version}\"" sh "git tag -a -m ${msg} ${version}" // Finally,push to the repo. // For this to work,the ssh keys must be available in Jenkins' ~/.ssh folder sh "git push origin ${version}" // Send a mail to the person responsible for manual testing and release. mail subject: 'A new version of KEIII is available for testing.',body: 'A new version of KEIII is available for testing and approval of release.',charset: 'utf-8',from: 'bob@computas.com',mimeType: 'text/plain',to: 'fs-tester@computas.com' stage 'Release' // User input showing up in the Jenkins UI. // If the timeout is reached,an exception is thrown and the build aborted. timeout(time: 120,unit: 'SECONDS') { input message: 'Do you want to release this version,' + version + ',of KEIII?',ok: 'Release' } // A catch block could deal with the exception. // In order to release to Nexus,deploy and access information needs to be made available in // a maven settings file. This configuration is copied into the file defined as // mavenSettingsFile from the corresponding managed file in Jenkins... def mavenSettingsFile = "${pwd()}/.m2/settings.xml" // ... using the configuration file build wrapper: wrap([$class: 'ConfigFileBuildWrapper',managedFiles: [ [fileId: '85adba0c-908b-4dbf-b3aa-65fe823e8984',targetLocation: "${mavenSettingsFile}"]]]) { // deploy to Nexus sh "${mvnHome}/bin/mvn deploy -s ${mavenSettingsFile} -f KnowledgeEditor/pom-deploy.xml -Dfs.version=${version}" } }