1. 程式人生 > 其它 >【jenkins】編寫配置spring-boot專案, CI/CD流水線專案

【jenkins】編寫配置spring-boot專案, CI/CD流水線專案

1. 新建專案

2. 新建流水線專案

輸入名稱,選擇流水線專案

3. 基礎配置

4. 根據自己需求配置對應引數

4. 配置觸發器

5. 配置觸發器高階選項

6. 配置高階專案選項-流水線指令碼

7. pipline指令碼示例

pipeline {
    agent any 
    stages {
        stage('PreEnv') {
            steps {
                script {
                    rootDir = rootDir
                }
                
echo 'rootDir: ${rootDir}' sh 'ifconfig' sh 'sudo apt install -y openjdk-11-jdk' sh 'sudo apt install -y maven' sh 'mvn -v' sh 'java -version' //sh 'which java' sh 'sudo update-alternatives --install /usr/local/java/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 3000
' //sh 'sudo update-alternatives --list java' sh 'sudo update-alternatives --auto java' //sh 'sudo update-alternatives --display java' sh 'java -version' } } stage('Build') { steps {
echo 'start Build......' checkout([$class: 'GitSCM', branches: [[name: '*/test']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: true, parentCredentials: false, recursiveSubmodules: false, reference: '', trackingSubmodules: false], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'xxxx']], submoduleCfg: [], userRemoteConfigs: [[url: 'git@xxxx:xxxx/xxxxx.git']]]) sh 'cd $rootDir && ls' sh 'cd $rootDir && mvn clean package -DskipTests' } } stage('Test') { steps { sh 'echo start Test........' sh 'cd $rootDir' writeFile file: 'stop.sh', text: "${STOP_SCRIPT}" sh 'ls' sh 'sudo bash ./stop.sh' sh 'nohup java -jar /home/jenkins/workspace/xxxxx/xxxxx/target/xxxx-0.0.1-SNAPSHOT.jar >> test.log &' sh 'ps -ef | grep xxxxx-0.0.1-SNAPSHOT.jar' sh 'kill $(ps -ef | grep xxxx-0.0.1-SNAPSHOT.jar | grep -v grep | awk \'{ print $2 }\')' sh 'sudo bash ./stop.sh' sh 'ps -ef | grep xxxxx-0.0.1-SNAPSHOT.jar' } } stage('Deploy') { steps { sh 'echo start Deploy........' //sh 'scp /home/jenkins/workspace/xxxxx-test/xxxxx/target/xxxx-0.0.1-SNAPSHOT.jar [email protected]:/home/xxxxx/xxxx/' // TODO execute '/home/xxxx/xxxx/script/upgrade.sh' remotely for redeploy. // TODO check redeploy state. } } } }