jenkinsfile or pipline implement micro-publishing service automatic rollback process


. 1
# ! / Usr / bin / Groovy Jenkinsfile the env 2 Node { . 3 // service name . 4 DEF SERVICE_NAME = " ** " . 5 // package name . 6 DEF service_bag_name = " **. JAR " . 7 // article library directory . 8 service_product = " / Data / Server / ** / Project-Demo " . 9 // working directory 10 Workspaces = " / Data / ** / ** - SERVICE_NAME $ {} " . 11 12 is IF (choice_status == "delop " && choice_build_number == " " ) { 13 is // pulling of git / Maven compile / archive finished 14 Stage ( ' the Build ' ) { 15 // Create Library article 16 WS ( ' / Data / Server / jenkinsworkspaces / pipline- Demo ' ) { . 17 // some Block 18 is // pulling git branch code . 19 git branch: ' Test ' , credentialsId: ' ** ' , URL: 'http://gitlab.lalala.cn/**/**.git ' 20 is // Maven compiler 21 is SH label: ' Maven compiler ' , Script: ' / Data / Server / Maven / bin / mvn Clean the install ' 22 is / / finished archiving, easy to post development verification is available finished package 23 is archiveArtifacts Artifacts: " ** / target / service_bag_name $ {} " , onlyIfSuccessful: to true 24 } 25 } 26 is // generating article 27 Stage ( " Artifacts " ) { 28 echo " Running env.BUILD_ID} $ {$ {ON} env.JENKINS_URL " 29 // Create Library article 30 the dir ( " $ {service_product} / {$ SERVICE_NAME} / {env.BUILD_ID} $ " ) { 31 is // some Block 32 the writeFile file: ' dummy ' , text: '' 33 is } 34 is // the files stored into the finished article library 35 // omitted here, by the finished article into the file storage database 36 } 37 [ 38 is Stage ( " the Test" ) { 39 echo " Testing .... " 40 echo " $ {} Workspaces " 41 is // omitted here, the finished document library to verify whether the product is available 42 is } 43 is 44 is Stage ( " the Deploy " ) { 45 echo " Deploying .... " 46 // 1 Find the file library products need to publish, by the way scp transmitted to the server directory service runs 47 // 2 . Find articles libraries need to publish files through jenkins sedn build artifacts over ssh way transmitted to the server running the service directory 48 } 49 50 }else if(choice_status=="rollback" && choice_build_number!="") { 51 stage("Rollback"){ 52 echo "rollbacking...." 53 echo "${service_name}" 54 echo "${service_bag_name}" 55 echo "${choice_build_number}" 56 sh label: '查找成品文件', script: """ls -lh ${service_product}/${service_name}/${choice_build_number}""" 57 } 58 59 } 60 }

Part of the code has been omitted, make up your own brain, service startup scripts need to write their own, temporarily herein described.

 

  

Guess you like

Origin www.cnblogs.com/ipyanthony/p/10966388.html