Skip to content

Instantly share code, notes, and snippets.

@rkivisto
Created September 23, 2020 15:26
Show Gist options
  • Save rkivisto/6fc98dbbc194882d2608edf967d2bd08 to your computer and use it in GitHub Desktop.
Save rkivisto/6fc98dbbc194882d2608edf967d2bd08 to your computer and use it in GitHub Desktop.

Revisions

  1. rkivisto created this gist Sep 23, 2020.
    73 changes: 73 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    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'
    }
    }
    }
    }