1

I installed JIRA Plugin for the jenkins. It add some action in Post-build Action menu. One of the action is JIRA: Update relevant issues.

When I try to access Environment Variable, it gives error.

WARNING: jira rest client get issue from jql search error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key '$MY_ISSUE_ID' for field 'issue' is invalid.]}]}
java.util.concurrent.ExecutionException: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key '$MY_ISSUE_ID' for field 'issue' is invalid.]}]}
    at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:262)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:91)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69)
    at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.get(DelegatingPromise.java:107)
    at hudson.plugins.jira.JiraRestService.getIssuesFromJqlSearch(JiraRestService.java:177)
    at hudson.plugins.jira.JiraSession.getIssuesFromJqlSearch(JiraSession.java:136)
    at hudson.plugins.jira.selector.JqlIssueSelector.findIssueIds(JqlIssueSelector.java:49)
    at hudson.plugins.jira.Updater.perform(Updater.java:85)
    at hudson.plugins.jira.JiraIssueUpdater.perform(JiraIssueUpdater.java:64)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
    at hudson.model.Build$BuildExecution.post2(Build.java:186)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
    at hudson.model.Run.execute(Run.java:1749)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:421)
Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key '$MY_ISSUE_ID' for field 'issue' is invalid.]}]}
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:176)
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:170)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:67)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:11)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:268)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:158)
    at com.google.common.util.concurrent.Futures$6.run(Futures.java:975)
    at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
    at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:149)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:134)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:170)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:268)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:158)
    at com.google.common.util.concurrent.Futures$6.run(Futures.java:975)
    at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
    at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:149)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:134)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:170)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$1$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:46)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:197)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient.runInContext(SettableFuturePromiseHttpPromiseAsyncClient.java:90)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable.run(SettableFuturePromiseHttpPromiseAsyncClient.java:192)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

$MY_ISSUE_ID is valid environment variable, and I am able to access it on other section of the build.

I tried issue=${XXXX}, issue=XXXX, issue="$XXXX" etc... but all gives error.

After answer I tried env. MY_ISSUE_ID but it give same error.

WARNING: jira rest client get issue from jql search error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key 'env. MY_ISSUE_ID' for field 'issue' is invalid.]}]}
java.util.concurrent.ExecutionException: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key 'env. MY_ISSUE_ID' for field 'issue' is invalid.]}]}
    at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:262)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:91)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69)
    at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.get(DelegatingPromise.java:113)
    at hudson.plugins.jira.JiraRestService.getIssuesFromJqlSearch(JiraRestService.java:177)
    at hudson.plugins.jira.JiraSession.getIssuesFromJqlSearch(JiraSession.java:132)
    at hudson.plugins.jira.selector.JqlIssueSelector.findIssueIds(JqlIssueSelector.java:46)
    at hudson.plugins.jira.Updater.perform(Updater.java:89)
    at hudson.plugins.jira.JiraIssueUpdater.perform(JiraIssueUpdater.java:64)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
    at hudson.model.Build$BuildExecution.post2(Build.java:186)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
    at hudson.model.Run.execute(Run.java:1749)
    at com.tikal.jenkins.plugins.multijob.MultiJobBuild.run(MultiJobBuild.java:76)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:421)
Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[The issue key 'env.MY_ISSUE_ID' for field 'issue' is invalid.]}]}
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:176)
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:170)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:67)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:11)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:295)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:185)
    at com.google.common.util.concurrent.Futures$6.run(Futures.java:975)
    at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
    at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:149)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:134)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:170)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:295)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:185)
    at com.google.common.util.concurrent.Futures$6.run(Futures.java:975)
    at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
    at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:149)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:134)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:170)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$1$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:46)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:197)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient.runInContext(SettableFuturePromiseHttpPromiseAsyncClient.java:90)
    at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable.run(SettableFuturePromiseHttpPromiseAsyncClient.java:192)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

What is the way to pass environment variable in jql for post build action.

When I gave issue=MYPROJECT-1234, it works fine. But, I want to set MYPROJECT-1234 as environment variable.

Job config.xml

<?xml version="1.0" encoding="UTF-8"?><com.tikal.jenkins.plugins.multijob.MultiJobProject>
  <actions/>
  <description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
  <keepDependencies>false</keepDependencies>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <concurrentBuild>false</concurrentBuild>
  <assignedNode>linux</assignedNode>
  <canRoam>false</canRoam>
  <properties>
    <com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github">
      <projectUrl>https://[email protected]/myteam/myproject</projectUrl>
      <displayName/>
    </com.coravy.hudson.plugins.github.GithubProjectProperty>
  </properties>
  <scm class="hudson.plugins.git.GitSCM">
    <configVersion>2</configVersion>
    <userRemoteConfigs>
      <hudson.plugins.git.UserRemoteConfig>
        <name>origin</name>
        <refspec>+refs/pull/*:refs/remotes/origin/pr/*</refspec>
        <url>https://[email protected]/myteam/myproject.git</url>
        <credentialsId>github_username_with_token</credentialsId>
      </hudson.plugins.git.UserRemoteConfig>
    </userRemoteConfigs>
    <branches>
      <hudson.plugins.git.BranchSpec>
        <name>${sha1}</name>
      </hudson.plugins.git.BranchSpec>
    </branches>
    <disableSubmodules>false</disableSubmodules>
    <recursiveSubmodules>false</recursiveSubmodules>
    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
    <remotePoll>false</remotePoll>
    <gitTool>Default</gitTool>
    <submoduleCfg class="list"/>
    <reference/>
    <gitConfigName/>
    <gitConfigEmail/>
    <extensions/>
  </scm>
  <triggers class="vector">
    <org.jenkinsci.plugins.ghprb.GhprbTrigger>
      <spec>H/5 * * * *</spec>
      <adminlist/>
      <allowMembersOfWhitelistedOrgsAsAdmin>false</allowMembersOfWhitelistedOrgsAsAdmin>
      <whitelist/>
      <orgslist/>
      <whiteListLabels/>
      <blackListLabels/>
      <cron>H/5 * * * *</cron>
      <triggerPhrase>^\s*check\s+everything\s*$</triggerPhrase>
      <skipBuildPhrase/>
      <onlyTriggerPhrase>false</onlyTriggerPhrase>
      <useGitHubHooks>true</useGitHubHooks>
      <permitAll>true</permitAll>
      <autoCloseFailedPullRequests>false</autoCloseFailedPullRequests>
      <whiteListTargetBranches>
        <org.jenkinsci.plugins.ghprb.GhprbBranch>
          <branch>staging</branch>
        </org.jenkinsci.plugins.ghprb.GhprbBranch>
      </whiteListTargetBranches>
      <extensions>
        <org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus>
          <commitStatusContext>pull request validation</commitStatusContext>
          <triggeredStatus>starting pull request validation...</triggeredStatus>
          <startedStatus>running pull request validation...</startedStatus>
          <completedStatus>
            <org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
              <message>All is well.</message>
              <result>SUCCESS</result>
            </org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
            <org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
              <message>Something went wrong. Investigate!</message>
              <result>FAILURE</result>
            </org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage>
          </completedStatus>
        </org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus>
      </extensions>
    </org.jenkinsci.plugins.ghprb.GhprbTrigger>
  </triggers>
  <builders>
    <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
      <phaseName>JIRA ID Validation</phaseName>
      <continuationCondition>SUCCESSFUL</continuationCondition>
      <executionType>PARALLEL</executionType>
      <phaseJobs>
        <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
          <jobName>cicd-myproject-prtest-jiraid</jobName>
          <currParams>true</currParams>
          <configs/>
          <abortAllJob>false</abortAllJob>
          <enableRetryStrategy>false</enableRetryStrategy>
        </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
      </phaseJobs>
    </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
    <com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
      <phaseName>Tox Validation</phaseName>
      <continuationCondition>SUCCESSFUL</continuationCondition>
      <executionType>PARALLEL</executionType>
      <phaseJobs>
        <com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
          <jobName>cicd-myproject-prtest-unittest</jobName>
          <currParams>true</currParams>
          <configs/>
          <abortAllJob>false</abortAllJob>
          <enableRetryStrategy>false</enableRetryStrategy>
        </com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
      </phaseJobs>
    </com.tikal.jenkins.plugins.multijob.MultiJobBuilder>
    <hudson.tasks.Shell>
      <command>#!/bin/bash
echo "MY_ISSUE_ID=`echo ${ghprbPullLongDescription} | grep -e 'MY-[0-9]\+' -o`" &gt; MY_issue.property
</command>
    </hudson.tasks.Shell>
    <EnvInjectBuilder>
      <info>
        <propertiesFilePath>$WORKSPACE/MY_issue.property</propertiesFilePath>
      </info>
    </EnvInjectBuilder>
    <hudson.plugins.jira.JiraIssueUpdateBuilder plugin="[email protected]">
      <jqlSearch>issue=${MY_ISSUE_ID}</jqlSearch>
      <workflowActionName>Ready for Review</workflowActionName>
      <comment>[Unit Testing|${BUILD_URL}] Done</comment>
    </hudson.plugins.jira.JiraIssueUpdateBuilder>
    <hudson.tasks.Shell>
      <command>#!/bin/bash
curl -X POST --data-urlencode 'payload={"text": "'"${ghprbPullLink}"' is ready for review"}' <slackurl>
</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers>
    <hudson.plugins.jira.JiraIssueUpdater plugin="[email protected]">
      <issueSelector class="hudson.plugins.jira.selector.JqlIssueSelector">
        <jql>issue=${MY_ISSUE_ID}</jql>
      </issueSelector>
      <labels/>
    </hudson.plugins.jira.JiraIssueUpdater>
  </publishers>
  <buildWrappers>
    <hudson.plugins.ansicolor.AnsiColorBuildWrapper>
      <colorMapName>xterm</colorMapName>
    </hudson.plugins.ansicolor.AnsiColorBuildWrapper>
  </buildWrappers>
</com.tikal.jenkins.plugins.multijob.MultiJobProject>
2
  • hi! please attach your Jenkinsfile so we know exactly what you were running to access and use the env variable. Commented Sep 4, 2018 at 20:29
  • @AnneTheAgile added config file.
    – Nilesh
    Commented Oct 5, 2018 at 14:11

1 Answer 1

1

You normally would access environment variables using the following syntax:

env.MY_ISSUE_ID

Typically you'll see the following in practice regarding envvars:

pipeline {
  agent any
  environment {
    MY_ISSUE_ID = 'PROJECT-1234'
  }
  stages {
    stage('Build') {
      steps {
        echo env.MY_ISSUE_ID
      }
    }
  }
}

or

node{
  stage('Build') {
    withEnv(["MY_ISSUE_ID=PROJECT-1234"]) {
      echo env.MY_ISSUE_ID
    }
  }
}
4
  • Thanks Casey, but I tried your answer, that not works with jira plugin.
    – Nilesh
    Commented Aug 31, 2018 at 14:06
  • 1
    Can you show us your pipeline?
    – casey vega
    Commented Aug 31, 2018 at 21:52
  • means XML config ?
    – Nilesh
    Commented Sep 1, 2018 at 21:47
  • I added config file in the question.
    – Nilesh
    Commented Oct 5, 2018 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.