Newer
Older
DummyJnkPL / Jenkinsfile
@Benoit Donneaux Benoit Donneaux on 26 Mar 2018 4 KB Fixup package name with lazyLabel
#!groovy

/*
 * This work is protected under copyright law in the Kingdom of
 * The Netherlands. The rules of the Berne Convention for the
 * Protection of Literary and Artistic Works apply.
 * Digital Me B.V. is the copyright owner.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Load Jenkins shared libraries common to all projects
def libLazy = [
    remote:           'https://code.in.digital-me.nl/git/DEVops/JenkinsLibLazy.git',
    branch:           env.BRANCH_NAME,
    credentialsId:    null,
]

library(
    identifier: "libLazy@${libLazy.branch}",
    retriever: modernSCM([
        $class: 'GitSCMSource',
        remote: libLazy.remote,
        credentialsId: libLazy.credentialsId
    ])
)

// Load Jenkins shared libraries to customize this project
def libCustom = [
    remote:           'ssh://git@code.in.digital-me.nl:2222/DEVops/JenkinsLibCustom.git',
    branch:           env.BRANCH_NAME,
    credentialsId:    'bot-ci-dgm-rsa',
]

library(
    identifier: "libCustom@${libCustom.branch}",
    retriever: modernSCM([
        $class: 'GitSCMSource',
        remote: libCustom.remote,
        credentialsId: libCustom.credentialsId
    ])
)

// Initialize configuration
lazyConfig(
    name:       'dummy-jenkins-pl',
    env:        [ 'DRYRUN=true' ],
    inLabels:   ['ubuntu-16', 'centos-7'],
    onLabels:   [ default: 'master', docker: 'docker', mac: 'mac', android: 'android', ],
    noPoll:     '.+_.+',
)

lazyStage {
    name = 'validate'
    tasks = [
        [
            run: {
                echo "This is my first task"
                gitLog('27e440f290d8bf95a3908cad03a5588fc2f2fe73')
                lazyGitPass('bot-ci-dgm', {
                	gitTag('test-0.0.1')
                }) 
                echo "Creating repo with packages"
                if (env.DRYRUN == 'true') { echo "DRYRUN is true = ${env.DRYRUN}" }
                if (env.DRYRUN == 'false') { echo "DRYRUN is false = ${env.DRYRUN}" }
            }, ],
        [ run: { echo "This is my second task" }, in: '*', on: 'docker' ],
        [ run: "third.sh", in: [ 'ubuntu-16', 'centos-7'], on: 'docker',],
        [ run: [ "fourth-a.sh", "fourth-b.sh"], on: 'mac' ],
        [ run: [ "fourth-a.sh", "fourth-b.sh"], on: 'android' ],
    ]
}

lazyStage {
    name = 'test'
    tasks = [
        [ run: { echo "This is my fith task" }, ],
        [
            run: { echo "This is my sixth task" },
            in: '*', on: 'docker'
        ],
        [
            run: [ 'junit.sh', 'jmeter.sh', ],
            in: '*', on: 'docker',
            post: { echo 'Archiving test reports' },
        ],
    ]
}

lazyStage {
    name = 'package'
    tasks = [
//        [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'windows', ]
//        [ run: { echo "Building packages"; echo "Archive packages"; }, on: 'mac', ]
        [
            run: {
                echo "Building packages";
                sh "mkdir -p target/packages && echo 'testpkg' > target/packages/\${LAZY_LABEL}.pkg"
            },
            in: [ 'ubuntu-16', 'centos-7', ],
            on: 'docker',
            post: {
                echo "Archiving packages"
                archiveArtifacts(artifacts: 'target/packages/**', allowEmptyArchive: false)
            },
        ],
    ]
}

lazyStage {
    name = 'publish'
    onlyif = ( env.LAZY_BRANCH == 'master' || env.PUBLISH == 'true' )
    tasks = [
        [
            pre: {
                echo "Unarchiving packages"
                unarchive(mapping:['target/packages/' : '.'])
                sh("ls -lA target/packages")
            },
            run: {
            	//withEnv(["DRYRUN=true"]) {
            	    echo "Creating repo with packages"
                    if (env.DRYRUN) { echo "DRYRUN is true = ${env.DRYRUN}" }
                    if (!env.DRYRUN) { echo "DRYRUN is false = ${env.DRYRUN}" }
            	//}
            },
            in: [ 'ubuntu-16', 'centos-7', ],
            on: 'docker',
            post: { echo "Publishing package repos" },
        ],
    ]
}