Valid use of environment directive

33 views
Skip to first unread message

Idan Adar

unread,
Apr 6, 2017, 11:08:18 AM4/6/17
to Jenkins Users
Is this a valid use of environment directive and variables in declarative pipeline?

pipeline {
   environment
{
       MY_VAR
= null
   
}  


   stages
{
      stage
("...") {
         steps
{
         MY_VAR
= "this_stage"
         
}
     
}
      stage
("...") {
         steps
{
         MY_VAR
= "this_stage2"
         
}
     
}
 
}
 
  post
{
      success
{
          slackSend
(
            message
: "$STAGE_NAME stage failed."
         
)
     
}
 
}

}


Idan Adar

unread,
Apr 6, 2017, 11:41:55 AM4/6/17
to Jenkins Users, rsan...@cloudbees.com
Perhaps Robert (CCed) can help?

Danny Rehelis

unread,
Apr 6, 2017, 11:57:13 AM4/6/17
to Jenkins Users, rsan...@cloudbees.com

Encapsulate MY_VAR in script { } blocked required to set a variable when using declarative pipeline inside a Stage.

No need to declare it with-in environment { }.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/76f4796b-9bee-455f-8c95-decdff8da6fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Idan Adar

unread,
Apr 6, 2017, 12:09:15 PM4/6/17
to Jenkins Users, rsan...@cloudbees.com
Yes, that's how I do it in my actual Jenkinsfile, but I thought maybe in a Declarative pipeline this works differently...

Andrew Bayer

unread,
Apr 6, 2017, 12:39:27 PM4/6/17
to jenkins...@googlegroups.com, Robert Sandell
No, that's definitely not intended to work that way, and it probably won't work. 

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4c7b1a85-8fde-435a-bee2-45275b787aa1%40googlegroups.com.

Idan Adar

unread,
Apr 6, 2017, 12:54:15 PM4/6/17
to Jenkins Users, rsan...@cloudbees.com
script { } it is... :/
Reply all
Reply to author
Forward
0 new messages