jenkins pipeline
作者:互联网
8.2.0 安装JDK
[root@harbor ~ ]# rpm -ivh jdk-8u172-linux-x64.rpm
[root@harbor ~ ]# rpm -ivh jenkins-2.249.1-1.1.noarch.rpm
[root@harbor ~ ]# yum install net-tools git -y
8.2.1配置maven
[root@harbor ~ ] cd /soft
[root@harbor ~ ] tar xvf apache-maven-3.6.2-bin.tar.gz
[root@harbor ~ ] mv apache-maven-3.6.2 /usr/local/
[root@harbor ~ ] vim /etc/profile
export MAVEN_HOME="/usr/local/apache-maven-3.6.2"
export PATH=${PATH}:${MAVEN_HOME}/bin
#应用配置
[root@harbor bin]# source /etc/profile
#获取maven home
[root@harbor bin]# mvn -v
[root@master-1 passport]# service jenkins restart
[root@master-1 passport]# chkconfig jenkins on
[root@harbor soft]# cp /var/lib/jenkins/hudson.model.UpdateCenter.xml /var/lib/jenkins/hudson.model.UpdateCenter.xml.bak
21fe93b1-e232-4a35-95ab-e75784572175
java -Dspring.cloud.nacos.discovery.server-addr=192.168.91.11:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.91.11:8848 \
-jar target/demo-0.0.1-SNAPSHOT.jar
pipeline{
agent any
environment {
def git_url="http://192.168.91.23/springcloud/passport.git"
def git_branch = "${branch}"
def git_auth = "21fe93b1-e232-4a35-95ab-e75784572175"
def project_version = "${release}-${UUID.randomUUID().toString()}"
def docker_nodes = "${nodes}"
def job_mvn = "${WORKSPACE}"
def mvn = '/usr/local/apache-maven-3.6.2/bin/mvn'
def image_name = 'provider-passport-demo'
def page_path = "${WORKSPACE}/target"
def project_path="/data/images/passport"
def remote_ip="192.168.91.18"
def app_name="provider-passport-demo"
def remote_yaml="/mnt/yaml/passport/provider-passport-demo.yaml"
}
stages{
stage('Git Checkout'){
steps{
echo 'check git'
checkout([
$class: 'GitSCM',
branches: [[name: "${git_branch}" ]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: "${git_auth}",
url: "${git_url}"
]]
])
}
}
stage('Manven Build'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "cd ${job_mvn} ; ${mvn} clean package -Dmaven.test.skip=true -U"
}
}
stage('Copy Jar'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "/usr/bin/cp -rf ${env.page_path}/demo-*-SNAPSHOT.jar ${project_path}"
}
}
stage('Docker Build'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "cd ${project_path} && docker build -t repo.hostscc.com/springcloud/${env.image_name}:${env.project_version} ."
}
}
stage('Push Docker'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "docker push repo.hostscc.com/springcloud/${env.image_name}:${env.project_version}"
}
}
stage('Apply Docker'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "ssh ${env.remote_ip} 'sed -i 's@${env.image_name}:.*@${env.image_name}:${env.project_version}@g' ${env.remote_yaml}';ssh ${env.remote_ip} '/usr/local/bin/kubectl apply -f ${env.remote_yaml}'"
}
}
stage('Replicas Docker'){
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps{
sh "ssh ${env.remote_ip} '/usr/local/bin/kubectl scale deployment ${env.app_name} --replicas=${env.docker_nodes}'"
}
}
}
post {
success {
sh "echo 'Success success'"
}
failure {
sh "echo 'Faild faild'"
}
}
}
java -Dspring.cloud.nacos.discovery.server-addr=192.168.91.11:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.91.11:8848 \
-jar provider-passport-0.0.1-SNAPSHOT.jar
8.2.0 安装JDK [root@harbor ~ ]# rpm -ivh jdk-8u172-linux-x64.rpm [root@harbor ~ ]# rpm -ivh jenkins-2.249.1-1.1.noarch.rpm [root@harbor ~ ]# yum install net-tools git -y 8.2.1配置maven [root@harbor ~ ] cd /soft [root@harbor ~ ] tar xvf apache-maven-3.6.2-bin.tar.gz [root@harbor ~ ] mv apache-maven-3.6.2 /usr/local/ [root@harbor ~ ] vim /etc/profile export MAVEN_HOME="/usr/local/apache-maven-3.6.2" export PATH=${PATH}:${MAVEN_HOME}/bin #应用配置 [root@harbor bin]# source /etc/profile #获取maven home [root@harbor bin]# mvn -v [root@master-1 passport]# service jenkins restart [root@master-1 passport]# chkconfig jenkins on [root@harbor soft]# cp /var/lib/jenkins/hudson.model.UpdateCenter.xml /var/lib/jenkins/hudson.model.UpdateCenter.xml.bak 21fe93b1-e232-4a35-95ab-e75784572175 java -Dspring.cloud.nacos.discovery.server-addr=192.168.91.11:8848 \ -Dspring.cloud.nacos.config.server-addr=192.168.91.11:8848 \ -jar target/demo-0.0.1-SNAPSHOT.jar pipeline{ agent any environment { def git_url="http://192.168.91.23/springcloud/passport.git" def git_branch = "${branch}" def git_auth = "21fe93b1-e232-4a35-95ab-e75784572175" def project_version = "${release}-${UUID.randomUUID().toString()}" def docker_nodes = "${nodes}" def job_mvn = "${WORKSPACE}" def mvn = '/usr/local/apache-maven-3.6.2/bin/mvn' def image_name = 'provider-passport-demo' def page_path = "${WORKSPACE}/target" def project_path="/data/images/passport" def remote_ip="192.168.91.18" def app_name="provider-passport-demo" def remote_yaml="/mnt/yaml/passport/provider-passport-demo.yaml" } stages{ stage('Git Checkout'){ steps{ echo 'check git' checkout([ $class: 'GitSCM', branches: [[name: "${git_branch}" ]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[ credentialsId: "${git_auth}", url: "${git_url}" ]] ]) } } stage('Manven Build'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "cd ${job_mvn} ; ${mvn} clean package -Dmaven.test.skip=true -U" } } stage('Copy Jar'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "/usr/bin/cp -rf ${env.page_path}/demo-*-SNAPSHOT.jar ${project_path}" } } stage('Docker Build'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "cd ${project_path} && docker build -t repo.hostscc.com/springcloud/${env.image_name}:${env.project_version} ." } } stage('Push Docker'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "docker push repo.hostscc.com/springcloud/${env.image_name}:${env.project_version}" } } stage('Apply Docker'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "ssh ${env.remote_ip} 'sed -i 's@${env.image_name}:.*@${env.image_name}:${env.project_version}@g' ${env.remote_yaml}';ssh ${env.remote_ip} '/usr/local/bin/kubectl apply -f ${env.remote_yaml}'" } } stage('Replicas Docker'){ when { expression { currentBuild.result == null || currentBuild.result == 'SUCCESS' } } steps{ sh "ssh ${env.remote_ip} '/usr/local/bin/kubectl scale deployment ${env.app_name} --replicas=${env.docker_nodes}'" } } } post { success { sh "echo 'Success success'" } failure { sh "echo 'Faild faild'" } } } java -Dspring.cloud.nacos.discovery.server-addr=192.168.91.11:8848 \ -Dspring.cloud.nacos.config.server-addr=192.168.91.11:8848 \ -jar provider-passport-0.0.1-SNAPSHOT.jar
标签:pipeline,harbor,currentBuild,result,env,jenkins,root,def 来源: https://www.cnblogs.com/gaoyuechen/p/16579493.html