Jenkins实践

Posted by Claire's Blog on September 2, 2022

实践说明: https://juejin.cn/post/6844903591417757710

Mac实践: https://juejin.cn/post/6844903984419831815

基础步骤:

  stages{
        //阶段1 获取代码
        stage("CheckOut"){
            steps{
                script{
                    println("获取代码")
                }
            }
        }
        stage("Build"){
            steps{
                script{
                    println("进行构建")
                }
            }
        }
        stage("Deploy"){
            steps{
                script{
                    println("进行部署")
                }
            }
        }
    }

拉取代码: 书写后,能够自动从指定地址,从指定分支checkout代码

steps{
    script{
        println("获取代码")
        git branch: 'main', credentialsId: 'gitlab', url: 'https://gitlab.yuanminglei.com/mpweixin/koaserver.git'
    }
}

直接调用脚本

 stage("Build"){
     steps{
         script{
             println("进行构建")
             sh "/opt/shell/jenkins/koaserver/build-koaserver-pipline.sh $GIT_TAG"
         }
     }
 }

ssh发布到其他服务器进行执行: sshPublisher是自带的模块

stage("Deploy"){
    steps{
        script{
            println("进行部署")
        }
        sshPublisher(
            publishers: [sshPublisherDesc
			    (configName: 'aliyun', transfers: 
			    	[sshTransfer
			    		(cleanRemote: false, 
			    		 excludes: '', 
			    		 execCommand: 'pwd', 
			    		 execTimeout: 120000, 
			    		 flatten: false, 
			    		 makeEmptyDirs: false, 
			    		 noDefaultExcludes: false, 
			    		 patternSeparator: '[, ]+', 
			    		 remoteDirectory: '/opt/test1', 
			    		 remoteDirectorySDF: false, 
			    		 removePrefix: 'target', 
			    		 sourceFiles: 'target/jenkins-test-build01-*.tar.gz'
			    		)
			    	], 
			    	usePromotionTimestamp: false, 
			    	useWorkspaceInPromotion: false, 
			    	verbose: false
			    )
		    ]
        )
    }
}

K8S/Docker Jenkins Nginx自动化部署VueJS项目

K8S/Docker Jenkins Nginx自动化部署Maven项目