phabricator-jenkins-plugin icon indicating copy to clipboard operation
phabricator-jenkins-plugin copied to clipboard

Report back build URL immediately with Jeninksfile/pipelines

Open altendky opened this issue 5 years ago • 1 comments

It would be nice to immediately report back the build URL instead of waiting until the build is done. I am using a pipeline so I would guess I would have to add a step other than the existing PhabricatorNotifier at the point in the build where I want the URL reported.

This looks to be implemented for non-pipelines.

https://github.com/uber/phabricator-jenkins-plugin/issues/133 https://github.com/ChaitanyaPramod/phabricator-jenkins-plugin/commit/cd3a3cb80ece4af282ae890cd1b0323725fc2e8e

altendky avatar Jun 07 '19 16:06 altendky

Hey, Not sure how helpful it is but I've been hitting my head against this today and came up with this scripted pipeline code (which needs the HTTPRequest plugin):

node() {
    stage("Report build to Phabricator") {
        // Report to Phabricator if this is a diff build
        if (params.DIFF_ID && params.DIFF_REPO && params.PHID ) {
            try{
                withCredentials([string(credentialsId: 'phab_arc_token', variable: 'ARC_TOKEN')]) {
                    def request_body = "api.token=${ARC_TOKEN}&buildTargetPHID=${params.PHID}&artifactKey=jenkins.uri&artifactType=uri&artifactData[uri]=${BUILD_URL}&artifactData[name]=%5B${JOB_NAME}%20%28Jenins%29%5D&artifactData[ui.external]=1"
                    httpRequest consoleLogResponseBody: true,
                        customHeaders: [[maskValue: false, name: 'Content-Type', value: 'application/x-www-form-urlencoded']],
                        httpMode: 'POST', ignoreSslErrors: true, requestBody: request_body, responseHandle: 'NONE', 
                        url: "${PHABRICATOR_URL}/api/harbormaster.createartifact",
                        validResponseContent: '"error_code":null'
                }
            } catch (err) {
                // Set build result to failure and report to Phabricator
                currentBuild.result = 'FAILURE'
                step([$class: 'PhabricatorNotifier', commentFile: '.phabricator-comment', commentOnSuccess: true,
                      commentSize: '1000', commentWithConsoleLinkOnFailure: true, coverageCheck: false,
                      coverageReportPattern: '**/coverage*.xml, **/cobertura*.xml, **/jacoco*.xml', 
                      coverageThreshold: 0.0, customComment: false, lintFile: '.phabricator-lint', lintFileSize: '100000', 
                      minCoverageThreshold: 100.0, preserveFormatting: false, processLint: false, uberallsEnabled: false])
                throw err
            }
        }
    }
}

For me this reports the build back to buildbot before it starts running on the node to do the job (it is running the HTTPRequest step on the master). If you need a declarative pipeline version I can try re-writing it for that (but I'm not as familiar with it :). Hope it helps.

timbrown5 avatar Sep 06 '19 13:09 timbrown5