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

not able to retrieve getCommentBody or getCommentURL from currentBuild.buildCauses #33

Closed
om3171991 opened this issue Aug 20, 2021 · 11 comments
Labels

Comments

@om3171991
Copy link

Hey Team,

We are trying to get github comment body to trigger different stages of pipeline using "when" expression and hence need commentbody to check which comment triggered this build ..like "testpr" to run tests, "deploypr" to do deployment, etc.

We have set up a multibranch pipeline and trigger build based on comments by developer.

Pipeline script:

pipeline {
agent { label 'any' }
stages {
stage('Pre-build') {
steps {
script {
dir("${WORKSPACE}") {
script {
echo "${glance_tag}"
echo "${currentBuild.buildCauses}" // [[_class:com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestCommentCause, shortDescription:GitHub pull request comment]]
def buildCauses = currentBuild.buildCauses
echo "$buildCauses.getCommentBody()" // gives null
echo "$buildCauses.getCommentUrl()" // gives null
echo "$buildCauses.shortDescription" // gives GitHub pull request comment
}
}
}
}
}
}
}

Can you please tell me - what I am doing wrong to fetch required information.

@om3171991 om3171991 added the bug label Aug 20, 2021
@devops-arena
Copy link

Try this
def triggerCause = currentBuild.rawBuild.getCause(com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestCommentCause)
echo("Build was started by ${triggerCause.commentBody}")

@om3171991
Copy link
Author

@devops-arena - Getting below error message -

Scripts not permitted to use method com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestCommentCause getCommentBody. Administrators can decide whether to approve or reject this signature.

@devops-arena
Copy link

@om3171991 You need to go to Manage Jenkins --> In-process Script Approval --> Approve the signature

@om3171991
Copy link
Author

@devops-arena - any other way around, don't have access to enable this. Our Jenkins is managed by the central team and it's a little tough to get this enabled.

bluesliverx pushed a commit to bluesliverx/github-pr-comment-build-plugin that referenced this issue Sep 20, 2021
@bluesliverx
Copy link
Contributor

I have pushed a fix for this, at least it has worked in other plugins. As soon as it builds correctly and gets merged, I'll do a new release.

@om3171991
Copy link
Author

@bluesliverx - Thanks. Much appreciated. Do we need to reconfigure the plugin to get this change under our Jenkins server?

bluesliverx added a commit that referenced this issue Sep 20, 2021
Fix #19 and #33, add comment author and whitelist cause fields
@bluesliverx
Copy link
Contributor

bluesliverx commented Sep 20, 2021

You would just need to upgrade the plugin on the Jenkins instance once it is released. No configuration changes would be necessary as it is a change to the classes themselves. This may take a few hours (up to a day) to the newest version in the repositories. Unfortunately, they have changed the release process since the last time I did this, and now I need to wait for jenkins-infra/repository-permissions-updater#2090 to be merged before I can release.

@bluesliverx
Copy link
Contributor

I changed the versioning scheme for incremental releases, and 58.v945be9f1661f has been released with the fix for this.

@bluesliverx
Copy link
Contributor

Looking at currentBuild.getBuildCauses() (or its override), I do not see the body/author/URL attributes included in the generated JSON. This is likely because of #37. I'll release this and check it later to see if that fixes the issue.

bluesliverx added a commit that referenced this issue Sep 21, 2021
#33 Add exported attributes to generate better JSON
@bluesliverx
Copy link
Contributor

I won't be able to upgrade our server until later tonight, so if anyone gets a chance to try out the latest release (61.v...) and see if it works, let me know.

@bluesliverx
Copy link
Contributor

Success! This build works great. Here is what I included in my Jenkinsfile:

echo("build causes: ${currentBuild.getBuildCauses()}")

Here is the output:

build causes: [[_class:com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestCommentCause, shortDescription:GitHub pull request comment, commentAuthor:saville, commentBody:this is comment, commentUrl:https://github.com/jenkinsci/github-pr-comment-build/pull/1#issuecomment-1234]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants