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 getting Jira issue ID from plugin in pipeline #361

Open
ggowins opened this issue Jul 29, 2021 · 0 comments
Open

Not getting Jira issue ID from plugin in pipeline #361

ggowins opened this issue Jul 29, 2021 · 0 comments
Labels
bug Release Drafter label

Comments

@ggowins
Copy link

ggowins commented Jul 29, 2021

Env details:

  • Jenkins version 2.289.3

  • Jira Plugin version v3.5

  • OS: Ubuntu 18.04

I am running into an issue calling jiraIssueSelector using the plugin inside a Jenkinsfile for a pipeline build. The plugin works as expected with a Freestyle job, but I get nothing inside a pipeline. Here's my basic Jenkinsfile, sanitized:

Reproduction steps

node {
    stage("checkout") {
        deleteDir()
        def scm = checkout BbS(branches: [[name: '*/unstable']], credentialsId: 'uuid for Bitbucket', extensions: [], id: 'another id', mirrorName: '', projectName: 'CodeTest', repositoryName: 'api', serverId: 'serverid', sshCredentialsId: '')
        def test = jiraIssueSelector(issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector']) 
        def jiraIssues = jiraIssueSelector(issueSelector: [$class: 'DefaultIssueSelector'])
        echo "Here are the issue IDs:"
        println test
        println jiraIssues
        echo "${test.size()}"
        echo "${jiraIssues.size()}"
       
        result = sh(returnStdout: true, script: 'git log -1 --oneline').trim()
        println result
        echo "${result.size()}"

        result2 = sh(returnStdout: true, script: 'git log -1 --pretty=oneline | grep -e \'[A-Z]\\+-[0-9]\\+\' -o | sort -u')
        println result2
        echo "${result2.size()}"          
    }
}

Results

When I run the job, here is what I get in the build console output:

Started by user me
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/jobs/DEV/jobs/pipelinetest/workspace
[Pipeline] {
[Pipeline] stage
[Pipeline] { (checkout)
[Pipeline] deleteDir
[Pipeline] checkout
The recommended git tool is: NONE
using credential uuid for Bitbucket
Cloning the remote Git repository
Cloning repository https://bitbucket.myserver.net/scm/code/api.git
 > git init /var/lib/jenkins/jobs/DEV/jobs/pipelinetest/workspace # timeout=10
Fetching upstream changes from https://bitbucket.myserver.net/scm/code/api.git
 > git --version # timeout=10
 > git --version # 'git version 1.9.1'
using GIT_ASKPASS to set credentials me login
 > git fetch --tags --progress https://bitbucket.myserver.net/scm/code/api.git +refs/heads/*:refs/remotes/api/* # timeout=10
 > git config remote.directory.url https://bitbucket.myserver.net/scm/code/api.git # timeout=10
 > git config --add remote.api.fetch +refs/heads/*:refs/remotes/api/* # timeout=10
Avoid second fetch
 > git rev-parse refs/remotes/api/unstable^{commit} # timeout=10
Checking out Revision 238b4ca42 (refs/remotes/api/unstable)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 38b4ca42 # timeout=10
Commit message: "Testing jenkins integration XXX-1234"
 > git rev-list --no-walk 38b4ca42 # timeout=10
Posting build status of INPROGRESS to MSI Bitbucket for commit id [38b4ca42] and ref 'null'
[Pipeline] jiraIssueSelector
[Pipeline] jiraIssueSelector
[Pipeline] echo
Here are the issue IDs:
[Pipeline] echo
[]
[Pipeline] echo
[]
[Pipeline] echo
0
[Pipeline] echo
0
[Pipeline] sh
+ git log -1 --oneline
[Pipeline] echo
189cf9e Testing jenkins integration XXX-1234
[Pipeline] echo
43
[Pipeline] sh
+ git log -1 --pretty=oneline
+ sort -u
+ grep -e [A-Z]\+-[0-9]\+ -o
[Pipeline] echo
XXX-1234

[Pipeline] echo
8
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Posting build status of SUCCESSFUL to MSI Bitbucket for commit id [38b4ca42] and ref 'null'
Finished: SUCCESS

Expected result:

That the jiraIssueSelector will get the Jira issue from the commit message.

Actual result:

When it runs, it appears that jiraIssueSelector is not finding anything, or doesn't have access to the build output. I tried calling the class two different ways, as shown in the script. I also added an alternate method to run a script for git log to get the latest commit and use regex to get the Jira issue, and it appears to work.

When I look at the examples, they reference passing in an SCM parameter to the jiraIssueSelector, but that appears to be deprecated.

Any info or tips on what I might be doing wrong?

@ggowins ggowins added the bug Release Drafter label label Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Release Drafter label
Projects
None yet
Development

No branches or pull requests

1 participant