在jenkins上安装salt-master,
pipeline{
agent{
node{
label 'master'
customWorkspace '/srv/salt/xxx/result'
}
}
parameters {
choice(name: 'app_name', choices: ['xxx-client', 'xx-server', 'xx'], description: 'app_name')
choice(name: 'server_name', choices: ['10.83.64.143'], description: 'server_name')
string(name: 'version',description: 'branch')
}
environment {
APP_NAME = "${params.app_name}"
}
tools {
maven 'M3'
jdk 'jdk1.8.0_92'
}
stages{
stage('get code'){
steps{
checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'svnchenbin', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: "https://10.83.32.2/svn/xx/xxx/branches/${params.version}/xx"]], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']])
}
}
stage('build'){
parallel {
stage('build-xx'){
when { environment name: 'APP_NAME', value: 'xxxx' }
steps{
sh 'mvn clean install -Dmaven.test.skip=true -f xxx/pom.xml'
}
}
stage('build-xx-x-server'){
when {
anyOf{
environment name: 'APP_NAME', value: 'xx-client'
environment name: 'APP_NAME', value: 'xx-server'
}
}
steps{
sh 'mvn clean install -Dmaven.test.skip=true -f pom.xml'
}
}
}
}
stage('deploy'){
steps{
sh "/usr/local/python3/bin/salt $server_name state.sls xxx/$app_name"
}
}
}
post {
always {
echo "Send notifications for result: ${currentBuild.currentResult}}"
sh '/usr/local/python3/bin/salt $server_name cmd.run "ps -ef|grep $app_name|grep -v grep"'
}
}
}