Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check on github says ok while stage failed on jenkins (using catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') in Jenkinsfile) #47

Closed
robkorv opened this issue Aug 12, 2019 · 2 comments

Comments

@robkorv
Copy link

robkorv commented Aug 12, 2019

Failed stage shows as success on Github

My Jenkinsfile looks like this:
Please look at the stage('aanmelder-python3') where catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') is used.

pipeline {
    agent any
    options {
        timeout(time: 30, unit: 'MINUTES')
        disableResume()
    }
    environment {
        TEST_POSTGRES_DB = 'testdb'
        TEST_POSTGRES_HOST = 'localhost'
        TEST_POSTGRES_PASSWORD = 'testing'
        TEST_POSTGRES_USER = 'testuser'
    }
    stages {
        stage('notify') {
            steps {
                slackSend message: "Building <${env.JOB_URL}|${env.JOB_NAME}>"
            }
        }
        stage('convert-service') {
            steps {
                sh './convert-service/script/cibuild'
            }
        }
        stage('aanmelder-python') {
            steps {
                script {
                    docker.image(
                        "convert-service:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
                    ).withRun(
                        "--name convert-service-${env.BRANCH_NAME.toLowerCase()}-${env.BUILD_NUMBER.toLowerCase()} --network aanmelder-shared"
                    ) {c ->
                        sh './script/cibuild'
                    }
                }
                junit 'python.xml'
                publishCoverage adapters: [coberturaAdapter('coverage.xml')],
                    sourceFileResolver: sourceFiles('STORE_ALL_BUILD'),
                    calculateDiffForChangeRequests: true
            }
        }
        stage('aanmelder-python3') {
            environment {
                PYTHON_VERSION = 'python3'
            }
            steps {
                catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                    script {
                        docker.image(
                            "convert-service:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
                        ).withRun(
                            "--name convert-service-${env.BRANCH_NAME.toLowerCase()}-${env.BUILD_NUMBER.toLowerCase()} --network aanmelder-shared"
                        ) {c ->
                            sh './script/cibuild'
                        }
                    }
                }
                junit 'python3.xml'
            }
        }
    }
    post {
        success {
            slackSend message: "Build success <${env.JOB_URL}|${env.JOB_NAME}>", color: 'good'
        }
        aborted {
            slackSend message: "Build aborted <${env.JOB_URL}|${env.JOB_NAME}>", color: 'warning'
        }
        failure {
            script {
                if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'production') {
                    slackSend channel: "alerts", message: "Build failure <${env.JOB_URL}|${env.JOB_NAME}>", color: 'danger'
                }
                slackSend message: "Build failure <${env.JOB_URL}|${env.JOB_NAME}>", color: 'danger'
            }
        }
    }
}

With catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure I can set the stage to fail while it doesn't break the whole build.

It looks like this in Jenkins:
Selectie_087

I would expect that the check on github would have the status FAILURE but it is marked as success.
Selectie_089

@pierreluctg
Copy link

Hi @jeffpearce can you please have a look?

Thank you

@robkorv
Copy link
Author

robkorv commented Oct 30, 2019

tnx @jeffpearce this works as expected 👌.

Selectie_101

@robkorv robkorv closed this as completed Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants