Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51610

Using different namespace with Pod yaml

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Hi

      I would like my Pods to be created in the namespace of my choice, and I would like to use several namespaces at the same time (depending on the job).

      With this Jenkinsfile, it works as expected :

      podTemplate(
          namespace: 'ci-space-test', label: 'mypod',
          containers: [
            containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:3.10-1-alpine', args: '${computer.jnlpmac} ${computer.name}')
          ]) {
      
          node ('mypod') {
              container(name: 'jnlp') {
                  sh "cat /var/run/secrets/kubernetes.io/serviceaccount/namespace"
              }
          }
      }
      

      But with this syntax, it does not:

      pipeline {
          agent {
              kubernetes {
                  label 'unique-pod-name'
                  defaultContainer 'container1'
                  yaml """
      apiVersion: v1
      kind: Pod
      metadata:
        namespace: my-pod-namespace
      spec:
        containers:
      
        - name: container1
          image: centos:7
          command:
          - cat
          tty: true
      """
              }
          }
          stages {
              stage('Print config') {
                  steps {
                      container('container1') {
                          sh 'echo "in container container1"'
                          sh 'env | sort'
                      }
                  }
              }
          }
      }
      

      What am I missing?

            surenpi Rick
            nodraak a a
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: