目的,通过jenkisn可以选择分支构建成 jar包,发送到后台服务器,然后启动后边服务器脚本,启动java项目
# 这个是声明式拉取代码,这个是成功的
pipeline {
agent any
stages {
stage('拉取代码') {
steps {
#添加内容
}
}
stage('切换分支') {
steps {
echo '开始拉release-test分支.....'
#添加内容
}
}
stage('编译打包') {
steps {
#添加内容
}
}
stage('发布到服务器') {
steps {
#添加内容
}
}
}
}
拉取完代码详情
第二步切换分支,由于咱们定义了tag,咱们可以选择分支构建,这一步就跳过了
编写完成的
完整版代码
pipeline {
agent any
stages {
stage('拉取代码') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '${tag}']], extensions: [], userRemoteConfigs: [[credentialsId: '100b584e-7f67-466f-8b93-9b9038e117a0', url: 'https://git.ibimfish.cn/Suzhou/pond.git']]])
}
}
// stage('切换分支') {
// steps {
// echo '开始拉release-test分支.....'
// git branch: "release-test",credentialsId: '100b584e-7f67-466f-8b93-9b9038e117a0', url: 'https://git.ibimfish.cn/Suzhou/pond.git'
// }
// }
stage('编译打包') {
steps {
sh 'mvn clean package install -Dmaven.test.skip=true -DarchetypeCatalog=local'
}
}
stage('拷贝jar包') {
steps {
sh 'ansible tomcat -m copy -a "src=/root/.jenkins/workspace/pipeline-pond/pond/target/pond.jar dest=/stet/"'
}
}
stage('启动脚本') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: '192.168.2.204', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''cd /stet
source /etc/profile
bash up.sh
''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
解决问题,因为你再片段生成器里面已经指定tag了 这里你就要更改一下
构建出来的jar包正常执行了,也是启动了但是jenkins构建显示有问题没有显示成功
解决方法
pipeline {
agent any
stages {
stage('拉取代码') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '${tag}']], extensions: [], userRemoteConfigs: [[credentialsId: '100b584e-7f67-466f-8b93-9b9038e117a0', url: 'https://git.ibimfish.cn/Suzhou/pond.git']]])
}
}
// stage('切换分支') {
// steps {
// echo '开始拉release-test分支.....'
// git branch: "release-test",credentialsId: '100b584e-7f67-466f-8b93-9b9038e117a0', url: 'https://git.ibimfish.cn/Suzhou/pond.git'
// }
// }
stage('编译打包') {
steps {
sh 'mvn clean package install -Dmaven.test.skip=true -DarchetypeCatalog=local'
}
}
stage('拷贝jar包') {
steps {
sh 'ansible tomcat -m copy -a "src=/root/.jenkins/workspace/pipeline-pond/pond/target/pond.jar dest=/root/upload/"'
}
}
stage('启动脚本') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: '192.168.2.204', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''cd /pipeline-pond
source /etc/profile
bash up.sh
''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '', usePty: true)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
ory: ‘’, remoteDirectorySDF: false, removePrefix: ‘’, sourceFiles: ‘’, usePty: true)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}