Jenkins 2019 in Docker(3)Blue Ocean and Pipeline

Jenkins2019inDocker(3)BlueOceanandPipeline

EnableBlueOcean

‘ManageJenkins’->‘ManagePlugins’->‘Available’->Check‘BlueOcean’and‘Downloadnowandinstallafterrestart'

RestartJenkinswheninstallationiscompleteandnojobsarerunning.

ClicktheButton‘OpenBlueOcean’togotonewUIordirectlyvisit

http://server/blue

FollowtheUItocreateanewpipeline

InGitHub.comintheSettings->DeveloperSettings->PersonalAccessTokens->Generatenewtoken

133ad445xxxxxxxxxa6cf9cff2

Injenkins,Credentials->System->Globalcredentials->SecretText

PutthetokeninSecret,GiveanIDasJenkins

MoreExamples

https://jenkins.io/doc/pipeline/examples/

https://github.com/jenkinsci/pipeline-examples

Cachethemavenlibraries

https://jenkins.io/doc/book/pipeline/docker/

Currently,IamusingthesimplestconfigurationfileJenkinsfile

pipeline{

agent{

docker{

image'maven:3.6.0-jdk-11'

args'-v$HOME/.m2:/root/.m2'

}

}

stages{

stage('CloneCode'){

steps{

git(url:'https://github.com/sillycat/NetsuiteConnector',branch:'master',changelog:true,poll:true,credentialsId:'yiyikang')

}

}

stage('CompileBuild'){

steps{

sh'mvnclean'

sh'mvninstall-DskipTests=true'

}

}

stage('UnitTest'){

steps{

sh'mvntest'

}

}

}

}

AgentDocstobuildwithDockerfile

https://jenkins.io/doc/book/pipeline/syntax/#agent

UsedockerENVtobuildtheapplication,Dockerfile.build

FROMmaven:3.6.0-jdk-11

MAINTAINERYiyiKang<[email protected]>

RUNapt-get-qqupdate

RUNapt-get-qqydist-upgrade

RUNcurl-fsSLhttps://get.docker.com|sh

Jenkinsfile

pipeline{

options{

buildDiscarder(logRotator(numToKeepStr:'10'))

}

agent{

dockerfile{

filename'Dockerfile.build'

args'-v$HOME/.m2:/root/.m2-v/var/run/docker.sock:/var/run/docker.sock'

}

}

stages{

stage('CloneCode'){

steps{

git(url:'https://github.com/sillycat/NetsuiteConnector',branch:'master',changelog:true,poll:true,credentialsId:'yiyikang')

}

}

stage('CompileBuild'){

steps{

sh'mvnclean'

sh'mvninstall-DskipTests=true'

}

}

stage('UnitTest'){

steps{

sh'mvntest'

}

}

stage('DockerImage'){

steps{

sh'dockerbuild-tsillycat/public:sillycat-netsuite.'

}

}

}

}

ItwillbuildthebuildingENVinDockerfile.build,thenJenkinsfilewillusethatENVtobuild.

References:

https://jenkins.io/zh/doc/book/blueocean/getting-started/

https://blog.csdn.net/neven7/article/details/53645215

https://jenkins.io/zh/doc/pipeline/tour/hello-world/

https://github.com/jenkinsci/pipeline-examples

https://medium.com/@gustavo.guss/jenkins-building-docker-image-and-sending-to-registry-64b84ea45ee9

https://jenkins.io/doc/book/pipeline/docker/

https://stackoverflow.com/questions/39542485/how-to-write-pipeline-to-discard-old-builds

相关推荐