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构建项目
选择分支,开始构建。