Thoughtworks公司pipeline脚本

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}"
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


什么是设计模式一套被反复使用、多数人知晓的、经过分类编目的、代码 设计经验 的总结;使用设计模式是为了 可重用 代码、让代码 更容易 被他人理解、保证代码 可靠性;设计模式使代码编制  真正工程化;设计模式使软件工程的 基石脉络, 如同大厦的结构一样;并不直接用来完成代码的编写,而是 描述 在各种不同情况下,要怎么解决问题的一种方案;能使不稳定依赖于相对稳定、具体依赖于相对抽象,避免引
单一职责原则定义(Single Responsibility Principle,SRP)一个对象应该只包含 单一的职责,并且该职责被完整地封装在一个类中。Every  Object should have  a single responsibility, and that responsibility should be entirely encapsulated by t
动态代理和CGLib代理分不清吗,看看这篇文章,写的非常好,强烈推荐。原文截图*************************************************************************************************************************原文文本************
适配器模式将一个类的接口转换成客户期望的另一个接口,使得原本接口不兼容的类可以相互合作。
策略模式定义了一系列算法族,并封装在类中,它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户。
设计模式讲的是如何编写可扩展、可维护、可读的高质量代码,它是针对软件开发中经常遇到的一些设计问题,总结出来的一套通用的解决方案。
模板方法模式在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中,使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤。
迭代器模式提供了一种方法,用于遍历集合对象中的元素,而又不暴露其内部的细节。
外观模式又叫门面模式,它提供了一个统一的(高层)接口,用来访问子系统中的一群接口,使得子系统更容易使用。
单例模式(Singleton Design Pattern)保证一个类只能有一个实例,并提供一个全局访问点。
组合模式可以将对象组合成树形结构来表示“整体-部分”的层次结构,使得客户可以用一致的方式处理个别对象和对象组合。
装饰者模式能够更灵活的,动态的给对象添加其它功能,而不需要修改任何现有的底层代码。
观察者模式(Observer Design Pattern)定义了对象之间的一对多依赖,当对象状态改变的时候,所有依赖者都会自动收到通知。
代理模式为对象提供一个代理,来控制对该对象的访问。代理模式在不改变原始类代码的情况下,通过引入代理类来给原始类附加功能。
工厂模式(Factory Design Pattern)可细分为三种,分别是简单工厂,工厂方法和抽象工厂,它们都是为了更好的创建对象。
状态模式允许对象在内部状态改变时,改变它的行为,对象看起来好像改变了它的类。
命令模式将请求封装为对象,能够支持请求的排队执行、记录日志、撤销等功能。
备忘录模式(Memento Pattern)保存一个对象的某个状态,以便在适当的时候恢复对象。备忘录模式属于行为型模式。 基本介绍 **意图:**在不破坏封装性的前提下,捕获一个对象的内部状态,并在该
顾名思义,责任链模式(Chain of Responsibility Pattern)为请求创建了一个接收者对象的链。这种模式给予请求的类型,对请求的发送者和接收者进行解耦。这种类型的设计模式属于行为
享元模式(Flyweight Pattern)(轻量级)(共享元素)主要用于减少创建对象的数量,以减少内存占用和提高性能。这种类型的设计模式属于结构型模式,它提供了减少对象数量从而改善应用所需的对象结