Created
          September 23, 2020 15:26 
        
      - 
      
- 
        Save rkivisto/6fc98dbbc194882d2608edf967d2bd08 to your computer and use it in GitHub Desktop. 
    upstream and downstream Pipelines that the upstream can choose the Docker image for the agent pod of the downstream Pipeline
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Upstream: | |
| pipeline { | |
| agent { | |
| kubernetes { | |
| // Rather than inline YAML, in a multibranch Pipeline you could use: yamlFile 'jenkins-pod.yaml' | |
| // Or, to avoid YAML: | |
| // containerTemplate { | |
| // name 'shell' | |
| // image 'ubuntu' | |
| // command 'sleep' | |
| // args 'infinity' | |
| // } | |
| yaml ''' | |
| apiVersion: v1 | |
| kind: Pod | |
| spec: | |
| containers: | |
| - name: shell | |
| image: ubuntu | |
| command: | |
| - sleep | |
| args: | |
| - infinity | |
| ''' | |
| // Can also wrap individual steps: | |
| // container('shell') { | |
| // sh 'hostname' | |
| // } | |
| defaultContainer 'shell' | |
| } | |
| } | |
| stages { | |
| stage('Main') { | |
| steps { | |
| sh 'cat /etc/os-release' | |
| build job: 'downstream', parameters: [string(name: 'IMAGE', value: 'ubuntu:18.04')] | |
| } | |
| } | |
| } | |
| } | |
| Downstream: | |
| pipeline { | |
| parameters { | |
| string defaultValue: 'ubuntu:latest', description: 'Docker image and tag to use', name: 'IMAGE', trim: true | |
| } | |
| agent { | |
| kubernetes { | |
| yaml """ | |
| apiVersion: v1 | |
| kind: Pod | |
| spec: | |
| containers: | |
| - name: shell | |
| image: $IMAGE | |
| command: | |
| - sleep | |
| args: | |
| - infinity | |
| """ | |
| defaultContainer 'shell' | |
| } | |
| } | |
| stages { | |
| stage('Main') { | |
| steps { | |
| sh 'cat /etc/os-release' | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment