[JIRA] (JENKINS-41187) [Declarative Pipeline] Stage "when" should have "stage" condition

2017-01-18 Thread bitwise...@gmail.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Liam Newman commented on  JENKINS-41187  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: [Declarative Pipeline] Stage "when" should have "stage" condition   
 

  
 
 
 
 

 
 Patrick Wolf I'm open to discussion of how it should look, but I think we need some form of this.  "Right now the use case described is easily done as shown."  Yes, like I said, for simple expressions things are fine, but for complex expressions this would get unwieldy very fast.  

 

stages {
stage ('Full Build') {
when {
_expression_ {
GIT_BRANCH = 'origin/' + sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
return GIT_BRANCH == 'origin/master' || params.FORCE_FULL_BUILD
}
}
}

stage ('Incremental Build') {
when {
_expression_ {
GIT_BRANCH = 'origin/' + sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
return !(GIT_BRANCH == 'origin/master' || params.FORCE_FULL_BUILD)
}
}
}
}
 

 Then repeat that condition over and over for other stages. Mediocre.  I see your point about the specific `stage {}` condition syntax I described being not great, but I also don't want to use general comparison operators if we can avoid them here. Also, stages run in serial and failure in a previous stage would generally stop the pipeline right?  Maybe this:  

 

stages {
stage ('Full Build') {
when {
_expression_ { return params.FORCE_FULL_BUILD }
}
}

stage ('Incremental Build') {
when {
stages('Full Build').skipped
}
}

stage ('Full Tests') {
when {
stages('Full Build').executed
}
}

stage ('Incremental Tests') {
when {
stages('Incremental Build').executed
}
}
}
 

 Or we could follow your status example: 

 

stages {
stage ('Full Build') {
when {
_expression_ { return params.FORCE_FULL_BUILD }
}
}

stage ('Incremental Build') {
when {
stages('Full Build').skipped
}
}

stage ('Full Tests') {
when {
stages('Full Build').succeeded 
}
}

stage ('Incremental Tests') {
when {
stages('Incremental Build').succeeded
}
}
}
 

  
 

  
 
 
 
 

 
 
  

[JIRA] (JENKINS-41187) [Declarative Pipeline] Stage "when" should have "stage" condition

2017-01-18 Thread pw...@cloudbees.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Patrick Wolf edited a comment on  JENKINS-41187  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: [Declarative Pipeline] Stage "when" should have "stage" condition   
 

  
 
 
 
 

 
 I don't like this syntax formatting.When I see this :{code:java}stage ('Incremental Build') {when {not { stage 'Full Build' }}}{code}I read it as when this Stage is not "Full Build". My first reaction is that is always true.If we want to say it is dependent in someway then we need to make that relationship explicit. When {{stage "Full Build " }} is not what? Not skipped, not run, not stable?  That isn't clear.Right now the use case described is easily done as shown. To me that is much more clear than the alternative.  We can explore having some {{stage}} conditions but they need to be clear.Maybe something like:{code:java}stage ('Incremental Build') {when { stage 'Full Build'  == SKIPPED}}{code}Or{code:java}stage ('Incremental Build') {when { stage 'Full Build'  == SUCCESS}}{code}Or{code:java}stage ('Incremental Build') {when { stage 'Full Build'  != UNSTABLE}}{code}  
 

  
 
 
 
 

 
 
 

 
 
 Add Comment  
 

  
 

  
 
 
 
  
 

  
 
 
 
 

 
 This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)  
 
 

 
   
 

  
 

  
 

   





-- 
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[JIRA] (JENKINS-41187) [Declarative Pipeline] Stage "when" should have "stage" condition

2017-01-18 Thread pw...@cloudbees.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Patrick Wolf commented on  JENKINS-41187  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: [Declarative Pipeline] Stage "when" should have "stage" condition   
 

  
 
 
 
 

 
 I don't like this syntax formatting. When I see this : 

 

stage ('Incremental Build') {
when {
not { stage 'Full Build' }
}
}
 

 I read it as when this Stage is not "Full Build". My first reaction is that is always true. If we want to say it is dependent in someway then we need to make that relationship explicit. When stage "Full Build is not what? Not skipped, not run, not stable? That isn't clear. Right now the use case described is easily done as shown. To me that is much more clear than the alternative. We can explore having some stage conditions but they need to be clear. Maybe something like: 

 

stage ('Incremental Build') {
when {
 stage 'Full Build'  == SKIPPED
}
}
 

 Or 

 

stage ('Incremental Build') {
when {
 stage 'Full Build'  == SUCCESS
}
}
 

 Or 

 

stage ('Incremental Build') {
when {
 stage 'Full Build'  != UNSTABLE
}
}
 

  
 

  
 
 
 
 

 
 
 

 
 
 Add Comment  
 

  
 

  
 
 
 
  
 

  
 
 

[JIRA] (JENKINS-41187) [Declarative Pipeline] Stage "when" should have "stage" condition

2017-01-18 Thread bitwise...@gmail.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Liam Newman created an issue  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
 Jenkins /  JENKINS-41187  
 
 
  [Declarative Pipeline] Stage "when" should have "stage" condition   
 

  
 
 
 
 

 
Issue Type: 
  Improvement  
 
 
Assignee: 
 Andrew Bayer  
 
 
Components: 
 pipeline-model-definition-plugin  
 
 
Created: 
 2017/Jan/18 10:52 PM  
 
 
Priority: 
  Minor  
 
 
Reporter: 
 Liam Newman  
 

  
 
 
 
 

 
 I'd like to create two stages, where if one runs the other doesn't - effectively and `if-else`. Right now I'd have to do something like this: 

 

stages {
stage ('Full Build') {
when {
_expression_ { return params.FORCE_FULL_BUILD }
}
}

stage ('Incremental Build') {
when {
_expression_ { return !params.FORCE_FULL_BUILD }
}
}
}
 

 For simple expressions, that's no problem. For complex expressions it gets tiresome. The `when {}` block needs a way to indicate `else`. This could be done (when combined with a logical `not` condition) by have a `stage` condition. Like so: 

 

stages {
stage ('Full Build') {
when {
_expression_ { return params.FORCE_FULL_BUILD }
}
}

stage ('Incremental Build') {
when {
not { stage 'Full Build' }
}
}
}
 

 This would also allow for stages to depend on previous stages in a clear fashion. For example: