pursue wind pursue wind
首页
Java
Python
数据库
框架
Linux
中间件
前端
计算机基础
DevOps
项目
面试
书
关于
归档
MacOS🤣 (opens new window)
GitHub (opens new window)
首页
Java
Python
数据库
框架
Linux
中间件
前端
计算机基础
DevOps
项目
面试
书
关于
归档
MacOS🤣 (opens new window)
GitHub (opens new window)
  • Docker

  • Jenkins

    • Jenkins - 介绍
    • 从零开始用Jenkins自动构建部署SpringBoot项目
    • 2020 Jenkins 总结
    • Coding Jenkins
    • Jenkins Pipeline
    • Jenkins之得到上次构建选择的分支
    • jenkins流水线脚本
      • jenkins流水线脚本
      • 分支选择
      • 合并分支
    • Jenkins自定义主题
    • Jenkins部署 jar包形式
    • Jenkins部署笔记
  • k8s
  • DevOps
  • Jenkins
pursuewind
2020-11-22
目录

jenkins流水线脚本

# jenkins流水线脚本

image

node{
    stage('get clone'){
       git url: 'ssh://git@192.168.0.55:2222/pocket/pocket-order-management.git'
    }

    //定义mvn环境
    def mvnHome = tool 'M3'
    env.PATH = "${mvnHome}/bin:${env.PATH}"

    stage('mvn test'){
        //mvn 测试
        sh "mvn test"
    }

    stage('mvn build'){
        //mvn构建
        sh "mvn clean install -Dmaven.test.skip=true"
    }

    stage('deploy'){
        //执行部署脚本
        echo "正在部署到服务器 ......"
        sshPublisher(
			publishers: [sshPublisherDesc(
				configName: '32g - yun - 120.25.165.220', 
				transfers: [sshTransfer(
					cleanRemote: false, 
					excludes: '', 
					execCommand: '''
						cd /home/mireal/pocket/pocket-order-management/target
						kill -9 `ps -ef | grep pocket-order-management | grep -v grep | awk \'{print $2}\'`
						source /etc/profile
						echo "---------------------正在启动应用程序---------------------"
						nohup java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=0.0.0.0:${debug_port} -jar pocket-order-management-1.0.0-SNAPSHOT.jar &
					''', 
					execTimeout: 120000, 
					flatten: false, 
					makeEmptyDirs: false, 
					noDefaultExcludes: false, 
					patternSeparator: '[, ]+', 
					remoteDirectory: 'pocket-order-management', 
					remoteDirectorySDF: false, 
					removePrefix: '', 
					sourceFiles: '**/*.jar')], 
				usePromotionTimestamp: false, 
				useWorkspaceInPromotion: false, 
				verbose: false
			)])
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
node {
   stage('git') { 
      git branch: '${mybranch}', url: 'git@git.dev.tencent.com:SZkexin/kexin-bnb.git'
   }
   stage('Build') {
      sh label: '', script: '/var/jenkins_home/gradle-4.5/bin/gradle build -x test'
   }
   stage('Results') {
      echo 'ok'
   }
}
1
2
3
4
5
6
7
8
9
10
11

# 分支选择

extend choice parameter

'git ls-remote --refs git@git.dev.tencent.com:mirrorming/Test-Git.git'.execute().text.readLines().collect { it.split('/')[2] }
1

# 合并分支

node {

    stage('拉取代码') {
        git 'git@git.dev.tencent.com:mirrorming/Test-Git.git'
    }
    stage('合并分支') {

        def SEL_BRANCHS = "$branchs"
        println SEL_BRANCHS
        
        def tempBranchName = "temp#"
        def asList = Arrays.asList(branchs.split(","))
        ArrayList allBranchs = new ArrayList<String>(asList);
        allBranchs.each { branch -> tempBranchName = tempBranchName.concat("_").concat(branch) }
        tempBranchName = tempBranchName.concat("_").concat(System.currentTimeMillis().toString().substring(10))
        
        println "选择的分支为:" + allBranchs
        def firstBranchName = allBranchs.remove(0)
        println "选择第一支分支:" + firstBranchName
        println "临时分支名为:" + tempBranchName


        sh "git checkout -b ${tempBranchName} origin/${firstBranchName}"
        println "还需要融合的分支有:" + allBranchs

        allBranchs.each { branch ->
            sh "git merge origin/${branch} -m 'merge'"
        }

        def pushCommand = "git push --set-upstream origin $tempBranchName"
        sh "git push --set-upstream origin ${tempBranchName}"

        println "==========ok==========="
    }
    stage('编译打包') {
        sh label: '', script: '/var/jenkins_home/gradle-5.0/bin/gradle build -x test'
        sh "git branch -D ${tempBranchName}"
    }
    stage('推送并执行') {
        sshPublisher(publishers: [
                sshPublisherDesc(
                        configName: 'localdeploy',
                        transfers: [sshTransfer(cleanRemote: false, excludes: '',
                                execCommand:
                                        '''
                                        BUILD_ID=DONTKILLME
                                        cd /usr/local/jenkins/pipeline-demo/
                                        cp target/bnb-0.0.1-SNAPSHOT.jar docker
                                        
                                        cd docker
                                        docker-compose down
                                        docker-compose build
                                        docker-compose up -d
                                        ''',
                                execTimeout: 120000,
                                flatten: false, makeEmptyDirs: false, noDefaultExcludes: false,
                                patternSeparator: '[, ]+', remoteDirectory: 'pipeline-demo',
                                remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*.jar,docker')],
                        usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Last Updated: 2023/01/30, 11:01:00
Jenkins之得到上次构建选择的分支
Jenkins自定义主题

← Jenkins之得到上次构建选择的分支 Jenkins自定义主题→

Theme by Vdoing | Copyright © 2019-2023 pursue-wind | 粤ICP备2022093130号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
  • 飙升榜
  • 新歌榜
  • 云音乐民谣榜
  • 美国Billboard榜
  • UK排行榜周榜
  • 网络DJ