Kubernetes plugin and podtemplate in declarative pipeline

22 views
Skip to first unread message

jado

unread,
Sep 11, 2019, 9:25:00 AM9/11/19
to Jenkins Users
Hi, 
I'm using Jenkins 2.176.2 and Kubernetes Plugin 1.18.1. 
I defined PodTemplate via GUI with RawYaml definition and i would like to use this in my declarative pipeline:

pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
}
}

 However pipeline execution stucks here:
Still waiting to schedule task
All nodes of label 'run-jenkins-buildslave-on-kube_84-7gg7p’ are offline

Pod is not being created on k8s. 
When i add any yaml definition as below:


pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
yaml """
spec:
containers:
- name: golang
image: golang:1.6.3-alpine
command:
- cat
tty: true
"""
}
}
 
Then POD has been started but it doesn't inherit from pod template - it runs 2 containers: jnlp and golang. How to use inheritance or some other mechanism so i dont need to define my pod in each pipeline?

My Kubernetes Pod template raw definition:
spec:      
  imagePullSecrets:
  - name: mysec
  containers:
  - name: maven                                                                
    image: maven:latest  
    imagePullPolicy: Always                                                    
    command:                                                                    
    - cat                                                                      
    tty: true
    env:
    - name: DOCKER_HOST
      value: tcp://localhost:2375
    resources: {}
 
  - name: dind
    image: docker:18.05-dind
    securityContext:
      privileged: true
    volumeMounts:
    - name: dind-storage
      mountPath: /var/lib/docker
    resources: {} 



jado

unread,
Sep 13, 2019, 1:52:54 AM9/13/19
to Jenkins Users
I've tried that before with no luck, but it starts to work finally - you don't define kubernetes template in the agent section, but reference to created one by the label assigned to it: 
pipeline {
agent {
label 'buildslave'
}

Reply all
Reply to author
Forward
0 new messages