Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-48135] Support multiple containers in declarative pipeline #306

Merged
merged 2 commits into from Apr 20, 2018

Conversation

carlossg
Copy link
Contributor

@carlossg carlossg commented Apr 6, 2018

Using the yaml syntax

JENKINS-48135
Supersedes #260

Example:

pipeline {
  agent {
    kubernetes {
      label 'mypod'
      defaultContainer 'jnlp'
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: maven
    image: maven:alpine
    command:
    - cat
    tty: true
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
"""
    }
  }
  stages {
    stage('Run maven') {
      steps {
        container('maven') {
          sh 'mvn -version'
        }
        container('busybox') {
          sh '/bin/busybox'
        }
      }
    }
  }
}

Copy link
Member

@Vlatombe Vlatombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. This defaultContainer could be useful as well for regular podTemplate.

@carlossg
Copy link
Contributor Author

carlossg commented Apr 9, 2018

I wouldn't know how to do implement defaultContainer in podTemplate

Copy link
Member

@abayer abayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the move to YAML? Just because it's more Kubernetes-ish? Because it doesn't feel Pipeline-ish at all.

@michaelneale
Copy link
Member

wouldn't at that point you want to put the kube ish yaml in a yaml file and have the pipeline just point to it? vs a mix of syntaxes in a string

@carlossg
Copy link
Contributor Author

@abayer because this has been a pain, new java code needs to be written for each possible kubernetes api option. Unless there is a way to generate the Java model automatically from Kubernetes this is always lacking all sorts of features from k8s API

@michaelneale I think that's the preferred option, you can use readFile step, at least in non-declarative. What I'm not sure is whether you can have Jenkins checkout scm to get that yaml file before the pod template is defined, the same way the Jenkinsfile is

@abayer
Copy link
Member

abayer commented Apr 10, 2018

@carlossg Ok - I know that can be a pain. So you don't actually parse the YAML, you just pass it off to Kubernetes directly? If so, I think I could write up some code to let you specify the YAML equivalent in Declarative syntax and translate it into a YAML string, if that'd be of any interest to you. Would make sense as a followup, though.

@berni2288
Copy link

The possibility to have the Kubernete configuration in a seperate file should be kept tho, such configurations can become quite big and complex and it bloats the Jenkinsfile.

@carlossg
Copy link
Contributor Author

@abayer

So you don't actually parse the YAML, you just pass it off to Kubernetes directly?

sort of, I load it with the kubernetes-client java library

That gives me model objects, but those are outside the plugin (not jenkins annotated)

Ideally the yaml would be kept in a separate file next to Jenkinsfile ie. Jenkinsagent but I'm not sure if the master would checkout extra files from git or just checks out Jenkinsfile

@etiennedi
Copy link

etiennedi commented Apr 19, 2018

Very interested in this PR as well, we really want to use declarative pipelines as well, but currently the fact that every docker image is the same leads to awkward install steps in each container. Additionally, we currently have to use kubectl inside each container to get the contents of secrets. Just mounting them through the template will be much nicer.

Also +1 on having the yaml file separate, but if this is a big effort I'd be quite happy about inline yaml as a first step and maybe adding the extraction later.

Since everything seems green in this PR, do we have an ETA for when this can/will be merged already? Thanks a bunch and really looking forward!

@dcarbajosa
Copy link

Hi, is there a way to not enforce in a declarative pipeline the initial container closure? It would be great to have an agent at pipeline level that can be used in most of the stages but doesn't collide with other agents that might be defined in parallel steps or at specific stage level. The problem with enforcing the initial closure is that if you want to run a stage in another node that is not a container it will break. So it would be really cool if we could have a solution that allows this, as it will optimize the pipelines by reducing the waiting time of procuring an agent. Currently the only way of avoiding this collisions is by defining agents at stage level that is not very optimal and time consuming. Many Thanks in advance.

@carlossg
Copy link
Contributor Author

@dcarbajosa not following, any example ? maybe better to follow up in jenkins-user mailing list

@carlossg carlossg merged commit 3886181 into master Apr 20, 2018
@carlossg carlossg deleted the JENKINS-48135 branch April 20, 2018 13:51
@carlossg carlossg changed the title [JENKINS-50533] Support multiple containers in declarative pipeline [JENKINS-48135] Support multiple containers in declarative pipeline Apr 23, 2018
@hkrpavan
Copy link

hkrpavan commented Dec 1, 2019

Can we define parent podTemplate in a shared library for declarative pipelines with out using jenkins config for "inheritFrom" feature?

Let me put the same question like this, Is there any other way rather than defining parent pod template in jenkins config for declarative pipelines and get inherited with child pod defined in yaml in jenkinsfile?

@derekslenk
Copy link

So a merge was made, but wasn't the fix? Any plans for this?

@hasmikg
Copy link

hasmikg commented Jul 7, 2021

So a merge was made, but wasn't the fix? Any plans for this?

Actually I have the same question here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet