[JIRA] (JENKINS-55771) Assign variable from shell output using declarative pipeline

1 view
Skip to first unread message

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 6:58:02 PM1/24/19
to jenkinsc...@googlegroups.com
Bryce Schober created an issue
 
Jenkins / Improvement JENKINS-55771
Assign variable from shell output using declarative pipeline
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: pipeline-build-step-plugin, pipeline-stage-step-plugin
Created: 2019-01-24 23:57
Environment: LTS 2.150.2
Priority: Minor Minor
Reporter: Bryce Schober
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 7:01:12 PM1/24/19
to jenkinsc...@googlegroups.com
Bryce Schober updated an issue
Change By: Bryce Schober
Currently, we can capture the output of a shell step inside of a {{script{}}} block, but have no way to do that in clean declarative pipeline syntax. For example, [this post on StackOverflow|https://stackoverflow.com/a/38783622] must instead

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 7:02:01 PM1/24/19
to jenkinsc...@googlegroups.com
Bryce Schober updated an issue
Change By: Bryce Schober
Component/s: workflow-durable-task-step-plugin
Component/s: pipeline-build-step-plugin
Component/s: pipeline-stage-step-plugin

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 7:04:01 PM1/24/19
to jenkinsc...@googlegroups.com
Bryce Schober updated an issue
Currently, we can capture the output of a shell step inside of a {{script{}}} block, but have no way to do that in clean declarative pipeline syntax. For example, [this post on StackOverflow|https://stackoverflow.com/a/38783622] must instead be:

{code:groovy}
// Git committer email
script {
  GIT_COMMIT_EMAIL = sh (
    script: 'git --no-pager show -s --format=\'%ae\'',
    returnStdout: true
  ).trim()
}
echo "Git committer email: ${GIT_COMMIT_EMAIL}"
{code}

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 7:04:02 PM1/24/19
to jenkinsc...@googlegroups.com

bryce.schober@gmail.com (JIRA)

unread,
Jan 24, 2019, 7:13:02 PM1/24/19
to jenkinsc...@googlegroups.com
Bryce Schober updated an issue
Currently, we can capture the output of a shell step inside of a {{script { }} } block, but have no way to do that in clean declarative pipeline syntax. For example, [this post on StackOverflow|https://stackoverflow.com/a/38783622] must instead be:

{code:groovy}
// Git committer email
script {
  GIT_COMMIT_EMAIL = sh (
    script: 'git --no-pager show -s --format=\'%ae\'',
    returnStdout: true
  ).trim()
}
echo "Git committer email: ${GIT_COMMIT_EMAIL}"
{code}

It also doesn't work to wrap it in a declarative {{environment}} block, though that may perhaps be a reasonable place to extend the syntax.

bryce.schober@gmail.com (JIRA)

unread,
Jan 25, 2019, 2:57:02 PM1/25/19
to jenkinsc...@googlegroups.com

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 25, 2019, 2:59:02 PM1/25/19
to jenkinsc...@googlegroups.com
Devin Nusbaum updated an issue
Change By: Devin Nusbaum
Component/s: pipeline-model-definition-plugin
Component/s: pipeline
Component/s: workflow-durable-task-step-plugin

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 25, 2019, 2:59:03 PM1/25/19
to jenkinsc...@googlegroups.com

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 25, 2019, 3:00:01 PM1/25/19
to jenkinsc...@googlegroups.com
Devin Nusbaum assigned an issue to Unassigned
Change By: Devin Nusbaum
Assignee: Devin Nusbaum

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 25, 2019, 3:00:02 PM1/25/19
to jenkinsc...@googlegroups.com
Devin Nusbaum commented on Improvement JENKINS-55771
 
Re: Assign variable from shell output using declarative pipeline

There might be an existing issue to track this kind of thing already, but IIUC it is somewhat by design (CC @abayer). In your example at least you could move your echo into the script you run, but perhaps that is not your real use case.

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 25, 2019, 3:08:01 PM1/25/19
to jenkinsc...@googlegroups.com
Devin Nusbaum edited a comment on Improvement JENKINS-55771
There might be an existing issue to track this kind of thing already, but IIUC it is somewhat by design (CC @ [~ abayer ] ). In your example at least you could move your echo into the script you run, but perhaps that is not your real use case.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 25, 2019, 4:15:02 PM1/25/19
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Duplicate
 

Yeah, this is one aspect of JENKINS-44376.

Change By: Andrew Bayer
Status: Open Resolved
Resolution: Duplicate

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:07 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Duplicate
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages