jenkinsci/stashnotifier-plugin

Input for Commit sha1?

Closed this issue · 3 comments

Hello! I've been trying to make the Stash notifier plugin work but it looks like for some reason or the other, the commit ID is not getting parsed into the notifyBitbucket example function that you guys wrote.

Here's the function I've been using:

    notifyBitbucket(
//            commitSha1: 'commit', <--- this is where I defined commitid as an input to the function and then passed env.GIT_COMMIT, but I think I just suck at Groovy to pull that off
//	    commitSha1: commitid,
//      commitSha1: '${sourceCommitHash}',
//        commitSha1: '${env.GIT_COMMIT}',
            credentialsId: 'NAME_OF_STASH_USERKEY_STORED',
            disableInprogressNotification: false,
            considerUnstableAsSuccess: true,
            ignoreUnverifiedSSLPeer: true,
            includeBuildNumberInKey: false,
            prependParentProjectKey: false,
            projectKey: '',
            stashServerBaseUrl: 'COMPANY_STASHURL',
            stashRootUrl: 'COMPANY_STASHURL')
}

And then I call the function with notifyBitbucket('INPROGRESS') or SUCCESS or FAILED later down in the Jenkinsfile.

The multiple comments are the different things I've tried. Having no commitSha1 field gives it a null value I believe and says that it couldn't find the 40 character commit. The parsing of '${env.GIT_COMMIT}' parsed that as a literal. Using '${sourceCommitHash}' said that that variable is not defined.

Any thoughts on what the commitSha1 field should be properly assigned to?

Thanks!


EDIT: The ONE thing that I was able to make work is to manually parse the git commit hash as such:

commitSha1: sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true)

I'm hoping there's a better way than that...

@sadatnfs do you have plugins like token macro installed? it's possible to use their notation. Also did you have checkout scm call as the git checkout step?

@scaytrase I do have checkout scm in my script blocks, and all that works since my actual job goes through all good.

And yes I do have the token macro plugin installed looks like, but I've never used it.

In case of checkout scm usage, git commit should be automatically applied without additional call arguments.

String lastBuiltSha1 = lastBuiltRevision.getSha1String();

The general usage flow is in the readme

node {
    checkout scm                            // Necessary so we know the current commit

    notifyBitbucket()                       // Notifies the Bitbucket instance of an INPROGRESS build

    try {
        // Do stuff

        currentBuild.result = 'SUCCESS'     // Set result of currentBuild !Important!
    } catch(err) {
        currentBuild.result = 'FAILED'      // Set result of currentBuild !Important!
    }

    notifyBitbucket()                       // Notifies the Bitbucket instance of the build result
}