Select Page

Jenkins pipeline for Kubernetes

How Jenkins pipeline should look for Kubernetes? There need to use just simple blocks where the declaring agent should be executed and what image we want to use. Nodes can be defined in a pipeline and then used, however, default execution always goes to the jnlp container. In this case, will need to specify the container you want to execute your task in. Of course need to install Kubernetes plugin and link it with a cluster that was deployed in production, do the basic configuration. Check this link for Kubernetes plugin: https://jenkins.io/doc/pipeline/steps/kubernetes/


def label = "someAgent"
def container = "containerName"
podTemplate(label: label) {
    node (label) {
        container (container) {
          stage("Build"){echo "Build}
          stage("Test"){echo "Test"}
        }
    }
}

Also may be interesting useful links in Groovy to operate strings: Groovy useful methods