0

I'm using Jenkins 2.346.2

The repository is located on bitbucket.org (cloud, not local server).

I want the build status to be sent to bitbucket and to be displayed as the PR build status.

I'm trying the plugin: https://plugins.jenkins.io/bitbucket-build-status-notifier/

The configuration is (multibranch pipeline project):


def notifyBitbucket(String state) {
    notifyBitbucket(
            commitSha1: 'a0e5012be0e8e89d122cc773a964c0en3a1a656b2',
            credentialsId: 'jenkins_bitbucket_ssh',
            disableInprogressNotification: false,
            considerUnstableAsSuccess: true,
            ignoreUnverifiedSSLPeer: true,
            buildStatus: state,
            buildName: 'Performance Testing',
            buildUrl: 'https://bitbucket.org',
            includeBuildNumberInKey: false,
            prependParentProjectKey: false,
            projectKey: '',
            stashServerBaseUrl: 'https://bitbucket.org')

}

But what I get is a returned bitbucket page saying 'Resource not found'. Currently, the only credentials I can use to connect to bitbucket is SSH key pair. And they work okay for pulling the code. I'm trying to use this key for the notification plugin as well. Is this wrong?

Could anyone let me know how to specify the path to the project in this case, please?

Bohdan Nesteruk
  • 794
  • 17
  • 42

1 Answers1

1

One option you can consider is using the Bitbucket API, which would remove the need for an external plugin. The endpoint you need to call is:

${BITBUCKET_API_HEAD}/commit/${env.COMMIT_HASH}/statuses/build

More on this in the documentation. Here is how I have done it:

httpRequest([
        acceptType        : 'APPLICATION_JSON',
        authentication    : '<credentials>',
        contentType       : 'APPLICATION_JSON',
        httpMode          : 'POST',
        requestBody       : '''{
            "key":"<unique-key>",
            "name":"PR-Branch-Build",
            "url":"<path-to-jenkins-build>/''' + env.BUILD_NUMBER + '''/pipeline",
            "description":"Build status: '''+ BUILD_STATUS +'''",
            "state":"'''+ BUILD_STATUS +'''"
        }''',
        responseHandle    : 'NONE',
        url               : "${BITBUCKET_API_HEAD}/commit/${env.COMMIT_HASH}/statuses/build",
        validResponseCodes: '200,201'
    ])
M B
  • 2,700
  • 2
  • 15
  • 20
  • Could you specify, please, what kind of credentials you use here and where you added them? For my ssh creds I'm getting the error from here: https://github.com/jenkinsci/http-request-plugin/blob/d98ff4e40ac0521df4a094c7862e50b289c2496d/src/main/java/jenkins/plugins/http_request/HttpRequestExecution.java#L198 – Bohdan Nesteruk Jul 28 '22 at 11:05
  • 1
    I'm using standard the Jenkins credential management system: https://www.jenkins.io/doc/book/using/using-credentials/ and the `` here refer to the credential ID that you get when using Jenkins credentials. – M B Jul 29 '22 at 04:54
  • I meant, what was the type of bitbucket credentials in Jenkins management creds system? Is it app password or api token? What I see from the httpRequest plugin code, it accepts only credentials of type: StandardUsernamePasswordCredentials or StandardCertificateCredentials: But I cannot understand what these types mean in jenkins credentials management. https://github.com/jenkinsci/http-request-plugin/blob/d98ff4e40ac0521df4a094c7862e50b289c2496d/src/main/java/jenkins/plugins/http_request/HttpRequestExecution.java#L239 – Bohdan Nesteruk Jul 29 '22 at 12:31
  • app password along with the normal username. Note that I use a service account, although that should make no difference – M B Jul 30 '22 at 04:43