Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50194

Build userId missing for a job being built by other Jobs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • jira-steps-plugin
    • None

      i have job1 with Jenkinsfile (example):

      #!groovy
      
      node('master') {
      try {
      stage('prepare') {
      }
      stage('check playbook') {
      }
      stage('deploy') {
      }
      stage('cleanup') {
      currentBuild.result = 'SUCCESS'
      deleteDir()
      build job: 'job2', wait: false
      }
      } catch(exc) {
      currentBuild.result = 'FAILURE'
      deleteDir()
      throw(exc)
      } finally {
      }
      }

      And job2 with Jenkinsfile:

      #!groovy
      
      node('master') {
      ...
      stage('jira update') {
      withEnv(['JIRA_SITE=LOCAL']) {
      version = [:]
      lastComment.eachMatch("(TEST)-[0-9]+") {
      a -> version[a[1]] = '';
      }
      version.each {
      projectKey, y -> println "project - $projectKey"
      def testVersion = [ name: nextTag, 
      released: false, 
      description: "${nextTag}", 
      project: projectKey ]
      def result = jiraNewVersion version: testVersion
      version[projectKey] = result.data
      }
      lastComment.eachMatch("(TEST)-[0-9]+") {
      a -> issueKey=a[0]; projectKey=a[1];
      
      try {
      def newVersion = version[projectKey]
      def testIssue = [fields: [fixVersions: [newVersion] ]]
      def editRes = jiraEditIssue idOrKey: issueKey, issue: testIssue
      println "version - $editRes"
      } catch(err) {
      echo "version error - $err"
      }
      
      try {
      def transitionInput = [transition: [id: 751]]
      def transRes = jiraTransitionIssue idOrKey: issueKey, input: transitionInput
      println "transition - $transRes"
      } catch(err) {
      echo "transition error - $err"
      }
      
      try {
      jiraAddComment idOrKey: issueKey, comment: "Success"
      } catch(err) {
      echo "comment error - $err"
      }
      }
      }
      }
      ...
      }

      If manually run job 2 (Build now) then in JIRA:

      Automatically created by: Matvey Kondratev from Build URL

      If manually run job1 then:

      Automatically created by: [~anonymous] from Build URL

      Maybe bug?

      /**
      * Return the current build user.
      *
      * @param causes build causes.
      * @return user name.
      */
      protected static String prepareBuildUser(List<Cause> causes) {
      String buildUser = "anonymous";
      if (causes != null && causes.size() > 0) {
      if (causes.get(0) instanceof UserIdCause) {
      buildUser = ((UserIdCause) causes.get(0)).getUserId();
      } else if (causes.get(0) instanceof UpstreamCause) {
      List<Cause> upstreamCauses = ((UpstreamCause) causes.get(0)).getUpstreamCauses();
      prepareBuildUser(upstreamCauses);
      }
      }
      return Util.fixEmpty(buildUser) == null ? "anonymous" : buildUser;
      }

      Jenkins log:

      INFO: While serving http://jenkins.local/job/ansible/job/job2/build: hudson.security.AccessDeniedException2: anonymous is missing the Job/Build permission

      JIRA log:

      2018-03-14 16:14:16,596 http-8080-11 WARN javabuild 974x2370843x1 zeo05a jenkins.local,127.0.0.1 /rest/api/2/issue/TEST-1 [labs.remoteapps.webhook.WebHookRegistrationManager] Failed to publish web-hooks for event com.atlassian.jira.event.issue.IssueEvent

      Jenkins: 2.73.1

      Jira Pipeline Steps: 1.3.1

      Jira: 5.1

        1. addCommentJob.png
          addCommentJob.png
          283 kB
        2. buildJob.png
          buildJob.png
          206 kB
        3. TEST1JIRA.png
          TEST1JIRA.png
          49 kB

            nrayapati Naresh Rayapati
            mkondratev Matvey Kondratev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: