donal
2018-04-17 8770adbbb32711ad0dd67fc2b1f37df9100595f8
ADD jenkinsfile for builds
1 files added
1 files modified
219 ■■■■■ changed files
Jenkinsfile 52 ●●●●● patch | view | raw | blame | history
Jenkinsfile.bak 167 ●●●●● patch | view | raw | blame | history
Jenkinsfile
@@ -6,16 +6,17 @@
    }
    environment {
        // TODO - remove this hard ref
        PROJECT_NAMESPACE = "donal-dev"
        PIPELINES_NAMESPACE = "donal-ci-cd"
        // GLobal Vars
        PIPELINES_NAMESPACE = "<YOUR_NAME>-ci-cd"
        APP_NAME = "todolist-api"
        JENKINS_TAG = "${JOB_NAME}.${BUILD_NUMBER}".replace("/", "-")
        JOB_NAME = "${JOB_NAME}".replace("/", "-")
        GIT_SSL_NO_VERIFY = true
        GIT_CREDENTIALS = credentials('jenkins-git-creds')
        GIT_URL = "gitlab-donal-ci-cd.apps.s8.core.rht-labs.com/donal/"
        GITLAB_DOMAIN = "gitlab-<YOUR_NAME>-ci-cd.apps.somedomain.com"
        GITLAB_PROJECT = "<YOUR_NAME>"
    }
    // The options directive is for configuration that applies to the whole job.
@@ -36,9 +37,26 @@
            when { branch 'master' }
            steps {
                script {
                  // Arbitrary Groovy Script executions can do in script tags
                  env.PROJECT_NAMESPACE = "donal-test"
                  env.E2E_TEST_ROUTE = "oc get route/${APP_NAME} --template='{{.spec.host}}' -n ${PROJECT_NAMESPACE}".execute().text
                    // Arbitrary Groovy Script executions can do in script tags
                    env.PROJECT_NAMESPACE = "<YOUR_NAME>-test"
                    env.NODE_ENV = "test"
                    env.E2E_TEST_ROUTE = "oc get route/${APP_NAME} --template='{{.spec.host}}' -n ${PROJECT_NAMESPACE}".execute().text
                }
            }
        }
        stage("prepare environment for develop deploy") {
            agent {
                node {
                    label "master"
                }
            }
            when { branch 'develop' }
            steps {
                script {
                    // Arbitrary Groovy Script executions can do in script tags
                    env.PROJECT_NAMESPACE = "<YOUR_NAME>-dev"
                    env.NODE_ENV = "dev"
                    env.E2E_TEST_ROUTE = "oc get route/${APP_NAME} --template='{{.spec.host}}' -n ${PROJECT_NAMESPACE}".execute().text
                }
            }
        }
@@ -49,9 +67,9 @@
                }
            }
            steps {
                git branch: 'develop',
                    credentialsId: 'jenkins-git-creds',
                    url: 'https://gitlab-donal-ci-cd.apps.s8.core.rht-labs.com/donal/todolist-api.git'
                // git branch: 'develop',
                //     credentialsId: 'jenkins-git-creds',
                //     url: 'https://gitlab-<YOUR_NAME>-ci-cd.apps.somedomain.com/<YOUR_NAME>/todolist-api.git'
                sh 'printenv'
                echo '### Install deps ###'
@@ -78,13 +96,11 @@
                    // Notify slack or some such
                }
                success {
                    echo "SUCCESS"
                    echo "Git tagging"
                    sh  '''
                            git tag -a ${JENKINS_TAG} -m "JENKINS automated commit"
                            # git push https://gitlab.apps.xpertex.rht-labs.com/donal/${APP_NAME}.git --tags
                            git push https://${GIT_CREDENTIALS_USR}:${GIT_CREDENTIALS_PSW}@${GIT_URL}${APP_NAME}.git --tags
                        '''
                    sh'''
                        git tag -a ${JENKINS_TAG} -m "JENKINS automated commit"
                        git push https://${GIT_CREDENTIALS_USR}:${GIT_CREDENTIALS_PSW}@${GITLAB_DOMAIN}/${GITLAB_PROJECT}/${APP_NAME}.git --tags
                    '''
                }
                failure {
                    echo "FAILURE"
@@ -107,7 +123,7 @@
                    '''
                echo '### Create Linux Container Image from package ###'
                sh  '''
                        oc project donal-ci-cd # probs not needed
                        oc project ${PIPELINES_NAMESPACE} # probs not needed
                        oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"ImageStreamTag\\",\\"name\\":\\"${APP_NAME}:${JENKINS_TAG}\\"}}}}"
                        oc start-build ${APP_NAME} --from-dir=package-contents/ --follow
                    '''
@@ -133,7 +149,7 @@
                    '''
                echo '### set env vars and image for deployment ###'
                sh '''
                    oc set env dc ${APP_NAME} NODE_ENV=dev
                    oc set env dc ${APP_NAME} NODE_ENV=${NODE_ENV}
                    oc set image dc/${APP_NAME} ${APP_NAME}=docker-registry.default.svc:5000/${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
                    oc rollout latest dc/${APP_NAME}
                '''
Jenkinsfile.bak
New file
@@ -0,0 +1,167 @@
pipeline {
    agent {
        // label "" also could have been 'agent any' - that has the same meaning.
        label "master"
    }
    environment {
        // GLobal Vars
        PIPELINES_NAMESPACE = "<YOUR_NAME>-ci-cd"
        APP_NAME = "todolist-api"
        JENKINS_TAG = "${JOB_NAME}.${BUILD_NUMBER}".replace("/", "-")
        JOB_NAME = "${JOB_NAME}".replace("/", "-")
        GIT_SSL_NO_VERIFY = true
        GIT_CREDENTIALS = credentials('jenkins-git-creds')
        GITLAB_DOMAIN = "gitlab-<YOUR_NAME>-ci-cd.apps.somedomain.com"
        GITLAB_PROJECT = "<YOUR_NAME>"
    }
    // The options directive is for configuration that applies to the whole job.
    options {
        buildDiscarder(logRotator(numToKeepStr:'10'))
        timeout(time: 15, unit: 'MINUTES')
        ansiColor('xterm')
        timestamps()
    }
    stages {
        stage("prepare environment for master deploy") {
            agent {
                node {
                    label "master"
                }
            }
            when { branch 'master' }
            steps {
                script {
                    // Arbitrary Groovy Script executions can do in script tags
                    env.PROJECT_NAMESPACE = "<YOUR_NAME>-test"
                    env.NODE_ENV = "test"
                    env.E2E_TEST_ROUTE = "oc get route/${APP_NAME} --template='{{.spec.host}}' -n ${PROJECT_NAMESPACE}".execute().text
                }
            }
        }
        stage("prepare environment for develop deploy") {
            agent {
                node {
                    label "master"
                }
            }
            when { branch 'develop' }
            steps {
                script {
                    // Arbitrary Groovy Script executions can do in script tags
                    env.PROJECT_NAMESPACE = "<YOUR_NAME>-dev"
                    env.NODE_ENV = "dev"
                    env.E2E_TEST_ROUTE = "oc get route/${APP_NAME} --template='{{.spec.host}}' -n ${PROJECT_NAMESPACE}".execute().text
                }
            }
        }
        stage("node-build") {
            agent {
                node {
                    label "jenkins-slave-npm"
                }
            }
            steps {
                // git branch: 'develop',
                //     credentialsId: 'jenkins-git-creds',
                //     url: 'https://gitlab-<YOUR_NAME>-ci-cd.apps.somedomain.com/<YOUR_NAME>/todolist-api.git'
                sh 'printenv'
                echo '### Install deps ###'
                sh 'scl enable rh-nodejs8 \'npm install\''
                echo '### Running tests ###'
                sh 'scl enable rh-nodejs8 \'npm run test:ci\''
                echo '### Running build ###'
                sh 'scl enable rh-nodejs8 \'npm run build:ci\''
                echo '### Packaging App for Nexus ###'
                sh 'scl enable rh-nodejs8 \'npm run package\''
                sh 'scl enable rh-nodejs8 \'npm run publish\''
            }
            // Post can be used both on individual stages and for the entire build.
            post {
                always {
                    archive "**"
                    junit 'reports/server/mocha/test-results.xml'
                    // publish html
                    // Notify slack or some such
                }
                success {
                    echo "Git tagging"
                    sh'''
                        git tag -a ${JENKINS_TAG} -m "JENKINS automated commit"
                        git push https://${GIT_CREDENTIALS_USR}:${GIT_CREDENTIALS_PSW}@${GITLAB_DOMAIN}/${GITLAB_PROJECT}/${APP_NAME}.git --tags
                    '''
                }
                failure {
                    echo "FAILURE"
                }
            }
        }
        stage("node-bake") {
            agent {
                node {
                    label "master"
                }
            }
            steps {
                echo '### Get Binary from Nexus ###'
                sh  '''
                        rm -rf package-contents*
                        curl -v -f http://admin:admin123@${NEXUS_SERVICE_HOST}:${NEXUS_SERVICE_PORT}/repository/zip/com/redhat/todolist/${JENKINS_TAG}/package-contents.zip -o package-contents.zip
                        unzip package-contents.zip
                    '''
                echo '### Create Linux Container Image from package ###'
                sh  '''
                        oc project ${PIPELINES_NAMESPACE} # probs not needed
                        oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"ImageStreamTag\\",\\"name\\":\\"${APP_NAME}:${JENKINS_TAG}\\"}}}}"
                        oc start-build ${APP_NAME} --from-dir=package-contents/ --follow
                    '''
            }
            post {
                always {
                    archive "**"
                }
            }
        }
        stage("node-deploy") {
            agent {
                node {
                    label "master"
                }
            }
            steps {
                echo '### tag image for namespace ###'
                sh  '''
                    oc project ${PROJECT_NAMESPACE}
                    oc tag ${PIPELINES_NAMESPACE}/${APP_NAME}:${JENKINS_TAG} ${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
                    '''
                echo '### set env vars and image for deployment ###'
                sh '''
                    oc set env dc ${APP_NAME} NODE_ENV=${NODE_ENV}
                    oc set image dc/${APP_NAME} ${APP_NAME}=docker-registry.default.svc:5000/${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
                    oc rollout latest dc/${APP_NAME}
                '''
                echo '### Verify OCP Deployment ###'
                openshiftVerifyDeployment depCfg: env.APP_NAME,
                    namespace: env.PROJECT_NAMESPACE,
                    replicaCount: '1',
                    verbose: 'false',
                    verifyReplicaCount: 'true',
                    waitTime: '',
                    waitUnit: 'sec'
            }
        }
    }
}