<commit_before>/**
 * List of global parameters:
 *
 * - JDK7
 *
 * List of global passwords:
 *
 * - BINTRAY_USER
 * - BINTRAY_API_KEY
 *
 * List of plug-ins:
 *
 * - Delivery pipeline
 * - Build pipeline
 * - Parameterized trigger
 * - Git
 * - Folders
 * - Set build name
 */

/**
 * Variables
 */

def REPOSITORY = 'nemerosa/versioning'
def PROJECT = 'versioning'
def LOCAL_REPOSITORY = '/var/lib/jenkins/repository/versioning'

/**
 * Folder for the project (making sure)
 */

folder {
    name PROJECT
}

/**
 * Generation for all branches
 */

URL branchApi = new URL("https://api.github.com/repos/${REPOSITORY}/branches")
def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())

branches.each {
    def BRANCH = it.name
    // Branch type
    def branchType
    int pos = BRANCH.indexOf('/')
    if (pos > 0) {
        branchType = BRANCH.substring(0, pos)
    } else {
        branchType = BRANCH
    }
    println "BRANCH = ${BRANCH}"
    println "\tBranchType = ${branchType}"
    // Keeps only some version types
    if (['master', 'feature', 'release', 'hotfix'].contains(branchType)) {
        // Normalised branch name
        def NAME = BRANCH.replaceAll(/[^A-Za-z0-9\.\-_]/, '-')
        println "\tGenerating ${NAME}..."
        // Folder for the branch
        folder {
            name "${PROJECT}/${PROJECT}-${NAME}"
        }

        // Package job
        job {
            name "${PROJECT}/${PROJECT}-${NAME}/${PROJECT}-${NAME}-01-package"
            logRotator(numToKeep = 40)
            deliveryPipelineConfiguration('Commit', 'Package')
            jdk 'JDK7'
            scm {
                git {
                    remote {
                        url "<EMAIL>:${REPOSITORY}.git"
                        branch "origin/${BRANCH}"
                    }
                    wipeOutWorkspace()
                    localBranch "${BRANCH}"
                }
            }
            steps {
                gradle 'clean build --info --profile'
                conditionalSteps {
                    condition {
                        status('SUCCESS', 'SUCCESS')
                    }
                    runner('Fail')
                    shell """\
# Copies the JAR to a local directory
cp build/libs/*.jar ${LOCAL_REPOSITORY}
"""
                }
            }
            publishers {
                archiveJunit("**/build/test-results/*.xml")
                tasks(
                        '**/*.java,**/*.groovy,**/*.xml,**/*.html,**/*.js',
                        '**/target/**,**/node_modules/**,**/vendor/**',
                        'FIXME', 'TODO', '@Deprecated', true
                )
            }
        }

        // Pipeline view<commit_msg>#4 Publication job<commit_after>/**
 * List of global parameters:
 *
 * - JDK7
 *
 * List of global passwords:
 *
 * - BINTRAY_USER
 * - BINTRAY_API_KEY
 *
 * List of plug-ins:
 *
 * - Delivery pipeline
 * - Build pipeline
 * - Parameterized trigger
 * - Git
 * - Folders
 * - Set build name
 */

/**
 * Variables
 */

def REPOSITORY = 'nemerosa/versioning'
def PROJECT = 'versioning'

/**
 * Folder for the project (making sure)
 */

folder {
    name PROJECT
}

/**
 * Generation for all branches
 */

URL branchApi = new URL("https://api.github.com/repos/${REPOSITORY}/branches")
def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())

branches.each {
    def BRANCH = it.name
    // Branch type
    def branchType
    int pos = BRANCH.indexOf('/')
    if (pos > 0) {
        branchType = BRANCH.substring(0, pos)
    } else {
        branchType = BRANCH
    }
    println "BRANCH = ${BRANCH}"
    println "\tBranchType = ${branchType}"
    // Keeps only some version types
    if (['master', 'feature', 'release', 'hotfix'].contains(branchType)) {
        // Normalised branch name
        def NAME = BRANCH.replaceAll(/[^A-Za-z0-9\.\-_]/, '-')
        println "\tGenerating ${NAME}..."
        // Folder for the branch
        folder {
            name "${PROJECT}/${PROJECT}-${NAME}"
        }

        // Package job
        job {
            name "${PROJECT}/${PROJECT}-${NAME}/${PROJECT}-${NAME}-01-package"
            logRotator(numToKeep = 40)
            deliveryPipelineConfiguration('Commit', 'Package')
            jdk 'JDK7'
            scm {
                git {
                    remote {
                        url "<EMAIL>:${REPOSITORY}.git"
                        branch "origin/${BRANCH}"
                    }
                    wipeOutWorkspace()
                    localBranch "${BRANCH}"
                }
            }
            steps {
                gradle 'clean build --info --profile'
            }
            publishers {
                archiveJunit("**/build/test-results/*.xml")
                tasks(
                        '**/*.java,**/*.groovy,**/*.xml,**/*.html,**/*.js',
                        '**/target/**,**/node_modules/**,**/vendor/**',
                        'FIXME', 'TODO', '@Deprecated', true
                )
                if (branchType == 'release') {
                    buildPipelineTrigger("${PROJECT}/${PROJECT}-${NAME}/${PROJECT}-${NAME}-02-publish") {
                        parameters {
                            gitRevision(true)
                        }
                    }
                }
            }
        }

        if (branchType == 'release') {
            // Publication job
            job {
                name "${PROJECT}/${PROJECT}-${NAME}/${PROJECT}-${NAME}-02-publish"
                logRotator(numToKeep = 40)
                deliveryPipelineConfiguration('Release', 'Publish')
                jdk 'JDK7'
                scm {
                    git {
                        remote {
                            url "<EMAIL>:${REPOSITORY}.git"
                            branch "origin/${BRANCH}"
                        }
                        wipeOutWorkspace()
                        localBranch "${BRANCH}"
                    }
                }
                steps {
                    gradle '''\
clean build publishPluginToBintray --info --profile
-PBINTRAY_USER=${BINTRAY_USER}
-PBINTRAY_API_KEY=${BINTRAY_API_KEY}
'''
                }
                publishers {
                    archiveJunit("**/build/test-results/*.xml")
                    tasks(
                            '**/*.java,**/*.groovy,**/*.xml,**/*.html,**/*.js',
                            '**/target/**,**/node_modules/**,**/vendor/**',
                            'FIXME', 'TODO', '@Deprecated', true
                    )
                }
            }
        }

        // Pipeline view
{'fraction_non_alphanumeric': 0.147493961352657, 'fraction_numerical': 0.004227053140096618, 'mean_word_length': 1.3140062871114215, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4351558', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1822, 'n_words': 356}