Skip to content

Instantly share code, notes, and snippets.

@LuczynskiDar
Last active May 16, 2020 06:56
Show Gist options
  • Save LuczynskiDar/3e93010fc2a1a4cab8254d97cec6cd88 to your computer and use it in GitHub Desktop.
Save LuczynskiDar/3e93010fc2a1a4cab8254d97cec6cd88 to your computer and use it in GitHub Desktop.
jenkins-files.md

Pipeline example

import groovy.json.JsonSlurper;

def base_url = "[email protected]:whatever/"
def config = new JsonSlurper().parseText(readFileFromWorkspace("$configPath"))

for (app in config.apps)
    pipelineJob("$app.name") {
        def gitRepoName = ("$app.gitRepoName" != 'null' ? ("$app.gitRepoName") : ("$app.name"))
        def ecrRepoName = ("$app.ecrRepoName" != 'null' ? ("$app.ecrRepoName") : ("$app.name"))
        parameters {
            stringParam('awsAccountId', "$config.awsAccountId", 'Aws account id')
            stringParam('awsRegion', "$config.awsRegion", 'Aws region')
            stringParam('ecrRepoName', "$ecrRepoName", 'Ecr repo name')
        }
        concurrentBuild(false)
        description("Do not modify this job. It is automatically generated via dsl")
        triggers {
            scm('H/5 * * * *')
        }
        logRotator {
            numToKeep(5)
        }
        definition {
            cpsScm {
                scm {
                    git {
                        remote {
                            url("$base_url" + "$gitRepoName" + '.git')
                            credentials('bitbucket')
                        }
                        branches((String[]) (("$app.branches" != 'null' ? ("$app.branches") : '*/master,*/tags/*')).tokenize(','))
                    }
                }
                lightweight()
                scriptPath("$app.scriptPath" != 'null' ? "$app.scriptPath" : "Jenkinsfile")
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment