How to use Jenkins docker-plugin:
Node {stage (' Clone Code ') {dir (' baas-ops ') {git credentialsid: ' Umarkci ', URL: ' [Email protected]******.com:umark/baas-ops.git '}} stage (' Unit testing ') { Docker.image (' BusyBox '). Inside {sh ' echo "Unit testing step!!!" ' }} stage (' Build ') {docker.image (' BusyBox '). Inside {sh ' echo Build Step!!! ' }} stage (' Image Build and Push ') {dir (' baas-ops/oboe/cli ') {Docker.wit Hregistry (' https://registry.******.com:8080 ', ' registry-hub-credentials ') {docker.build (' O Boe-cli '). push (' T1 ')}}} stage (' Deploy images ') {TR y {sh ' docker rm-f test '} catch (e) {} docker.image (' oboe-Cli:t1 '). Run ('-p 80:3000--name test ')}}
Jenkins Kubernetes-plugin Plugin uses:
Podtemplate (Label: ' Test ', SecurityContext: [runasuser: ' Root '], containers: [Containertemplate (Name: ' JNLP ', Image: ' Registry.******.com:8088/jnlp-slave:alpine ', args: ' ${computer.jnlpmac} ${computer.name} '), ContainerTempla TE (name: ' Docker ', Image: ' Docker:stable ', ttyenabled:true, command: ' Cat ')], volumes: [HOSTPATHVO Lume (hostpath: '/var/run/docker.sock ', Mountpath: '/var/run/docker.sock '),//Hostpathvolume (hostpath: '/tmp/test ', Mountpath: '/data '), Persistentvolumeclaim (claimname: ' Jenkins-slave-gfs ', Mountpath: '/home/jenkins ', ReadO Nly:false)] {node (' Test ') {def registryaddr= ' registry.******.com:8080 ' stage (' Build imag E ') {git credentialsid: ' oschina-test ', url: ' [email protected]:yonchin/jenkins-test.git ' Container (' docker ') {sh ' docker build-t ${registryaddr}/busybox:k8s. " }} stage (' Push IMage ') {container (' Docker ') {withcredentials ([Usernamepassword (credentialsid: ' Reg Istry-hub-credentials ', passwordvariable: ' Registrypass ', usernamevariable: ' Registryuser ')]) { SH "Docker login ${registryaddr}-u ${env.registryuser}-P ${registrypass}" sh "docker Push ${registryaddr}/busybox:k8s "}}}" Note: Where Credentialsid is going to be in Jenkins Credentials, System-I, Global credentials (unrestricted), ADD credentials is created in advance. Where, Registryuser and registrypass These two variables are automatically obtained in ' ADD credentials ' defined to the user name and password.
Jenkins Docker-plugin and Kubernetes-plugin plug-in practical case