def getHost(ip){
def remote = [:]
remote.name = 'server-${ip}'
remote.host = ip
remote.port = 22
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: '31ed3f9c-3e80-496d-9733-98b78db29128', passwordVariable: 'password', usernameVariable: 'userName')]) {
remote.user = "${userName}"
remote.password = "${password}"
}
return remote
}
def imageName="10.1.80.126:9001/library/etecsa-server-config-test"
def imageTag="latest"
def prjName="etecsa-server-config-test"
def register="http://10.1.80.126:9001"
pipeline {
agent any
environment{
def server = ''
}
stages {
stage('init-server'){
steps {
script {
server = getHost("10.1.80.126")
}
}
}
stage('Pre'){
steps {
sh label: '', script: """ if [ \$(docker ps -a | grep -i $imageName | wc -l) -eq 1 ]; then
docker stop $prjName
docker rm -v -f $prjName
fi
if [ \$(docker images | grep -i $imageName | wc -l) -eq 1 ]; then
docker rmi -f $imageName
fi
"""
}
}
stage('BuildJar') {
steps {
echo '拉取代码'
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: '8be443f3-8a57-4ce3-9905-1433c9f1b333', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'svn://10.1.80.111/ETECSA-SERVER']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']])
withMaven(maven: 'maven', mavenSettingsConfig: '62b4b95d-fe93-45f7-8eea-e551823d1b98') {
sh label: '', script: 'mvn clean install -pl ETECSA-SERVER-CONFIG-CENTER -am -amd -Dmaven.test.skip=true'
}
}
}
stage('DockerBuild') {
steps {
dir ("ETECSA-SERVER-CONFIG-CENTER/") {
script {
def image = docker.build("$imageName:$imageTag")
docker.withRegistry("$register", 'a2609603-66d9-4cfe-9ddf-e8ace35c1279'){
image.push()
}
}
}
}
}
stage('Run'){
steps {
script {
sshCommand remote: server, command: """
svn checkout svn://10.1.80.111/ETECSA-SERVER/DOCKER-COMPOSE --username zhanghao --password 123456
cd DOCKER-COMPOSE
docker-compose up -d $prjName
"""
}
}
}
}
}
jenkins pipline 脚本
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...