Jenkins 2019 in Docker(4)Cluster using Docker
Jenkins2019inDocker(4)ClusterusingDocker
Checkthedockerversionon2machines
>docker--version
Dockerversion18.09.2,build6247962
MasterandSlave,setthepublickeytossheachother,majorisjusttheMasterneedtoSSHtoSlave
ManageJenkins—>ManageNodes—>Wecanseethereisonemasternodeswith60.27GBdiskspace
NewNode—>NodeName:slave1—>PermanentAgent
Inthenextpage,Iputsomeinformationsasfollow:
Name:slave1
#ofexecutors:2
Remoterootdirectory:/opt/jenkins/jensins_home_slave
Labels:slave1
Usage:Usethisnodeasmuchaspossible
Launchmethod:LaunchagentagentsviaSSH
Host:IPaddressoftheslavemachine
Credentials:Iuserootanduseprivatekeytosshtotheslave
HostKeyVerificationStrategy:NonverifyingVerificationStrategy
Availability:Keepthisagentonlineasmuchaspossible.
HereismyJenkinsfileinpipelinescript:
pipeline{
options{
buildDiscarder(logRotator(numToKeepStr:'50'))
}
agent{
dockerfile{
filename'deployment/jenkins/Dockerfile.build'
args'-uroot:root-v$HOME/.m2:/root/.m2-v/var/run/docker.sock:/var/run/docker.sock'
}
}
stages{
stage('CloneCode'){
steps{
git(url:'https://github.com/sillycatInc/NetsuiteConnector',branch:'master',changelog:true,poll:true,credentialsId:'github')
}
}
stage('CompileandUnitTest'){
steps{
sh'mvnclean'
sh'mvncompile'
sh'mvn-Dtest=WsClientServiceTesttest'
}
}
stage('ReleasetoArtifactory'){
steps{
sh'mvnpackage-DskipTests=true'
withCredentials([string(credentialsId:'artifactory',variable:'TOKEN')]){
sh'''
set+x
jfrogrtconfig--urlhttps://artifactory.sillycat.com/artifactory--userkikokang--apikey$TOKEN--interactive=false
jfrogrtutarget/netsuiteconnector-*-bundle.tar.gzsillycat-java/com/sillycat/netsuiteconnector/1.0/
rm-frtarget
'''
}
}
}
}
}
IthinkitisnotgoodtouserootandIdonotthinkdirectlyrunonslaveisagoodidea.Iwillcheckothersolutionlater.
References:
https://www.cnblogs.com/stulzq/p/9297260.html
https://www.jianshu.com/p/ab5c0bbe02de
https://chanjarster.github.io/post/jenkins-cluster/
https://my.oschina.net/mrpei123/blog/1975952
https://stackoverflow.com/questions/48223200/jenkins-pipeline-using-docker-on-existing-slaves