Jenkins配置构建Golang项目

1. 环境

这里,我已经安装好了Jenkins环境,重新安装可参考,并且安装好了JDK、Tomcat、Git、Maven。

2. Jenkins部署项目

2.1 新建任务

2.2 配置

这里,我举例配置一个编译golang项目的流水线构建项目。

描述:

数据联网系统后台数据接入服务,基于Golang持续构建。
<li>
    取包路径:
    <a href="http://172.20.32.143/Melineye_DAG/Melineye_DAG-gosrc/">点这里</a>
</li>
<li>
    仓库路径:
    <a href="https://gitlab.sit.com.cn/Melineye_MPG/DAG_gosrc.git">https://gitlab.sit.com.cn/Melineye_MPG/DAG_gosrc.git</a>
</li>

启用项目安全:

参数化构建过程:

 流水线:

#!groovy
pipeline {
    agent {
        node {
            label "master"
        }
    }
    options {
        timestamps()
        disableConcurrentBuilds()
        buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')
    }
    parameters {
        listGitBranches branchFilter: '.*', credentialsId: '848c0983-c84a-4f80-afe3-597c74c305d5', defaultValue: 'origin/develop', name: 'go_branch', quickFilterEnabled: false, remoteURL: 'https://gitlab.sit.com.cn/Melineye_MPG/DAG_gosrc.git', selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '.*', type: 'PT_BRANCH' 
    }
    environment {
        storage = 'sailing.com'
        module_version = 'v1'
    }
    stages {
        stage ('checkout'){
            steps {
				ws('/home/sailing/DAG_gosrc') {
					echo '更新gosrc仓库代码'
					checkout([$class: 'GitSCM', branches: [[name: '$go_branch']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'src'], [$class: 'CheckoutOption', timeout: 30], [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false, timeout: 30], [$class: 'CleanBeforeCheckout', deleteUntrackedNestedRepositories: true]], gitTool: 'git', submoduleCfg: [], userRemoteConfigs: [[credentialsId: '848c0983-c84a-4f80-afe3-597c74c305d5', url: 'https://gitlab.sit.com.cn/Melineye_MPG/DAG_gosrc.git']]])
					echo '完成更新gosrc仓库代码'
				}
			}
        }
		
        stage('compile') {
           steps {
				ws('/home/sailing/DAG_web') {
					script {
						sh '''
						pwd
						cd /home/sailing/DAG_gosrc
						pwd
						cd src
						source /etc/profile
						source /root/.bash_profile
						echo "开始编译go后台"
						sh make.sh
						echo "开始打包go后台"
						sh build.sh
						cd ..
						pwd
						
						echo "创建分支目录"
						if [ -e output ];then
							rm -fr output
						fi
						mkdir -p output/${go_branch#*/*/}
						
						echo "安装包拷贝到output目录分支下"
						mv dnpsservice.tar.gz ./output/${go_branch#*/*/}
						
						echo "安装包sha256加密"
						cd output/${go_branch#*/*/}
						file=$(ls *.gz)
						name=${file%.*}
						sha256sum $name.gz > $name.gz.sha256
						chmod 555 ./*.gz*
						cd -
						pwd
						
						echo "拷贝安装包到发布路径"
						\\cp -R output/${go_branch#*/*/}/  /home/sailing/releasePkg/Melineye_DAG/Melineye_DAG-gosrc/
						
						echo "删除output目录"
						rm -rf output/
						
						'''
					}
				}
			}
			
        }
       
    }
}

2.3构建项目

选择分支,开始构建。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值