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

SCM (Git) Will Not Notify Pipeline Before Execution

    XMLWordPrintable

Details

    Description

      I work in bitbucket which uses a hook to notify our jenkins server on commit (or if manually triggered in a pull request). I've noticed that, when I make a new pipeline job from SCM (git), onNotifyCommit won't look at the new job until after I've manually run the job and it has completed.

      A bit more details on the job:

      • I did specify an empty poll interval, which allowed my other maven jobs to be properly notified.
      • I haven't specified any additional behaviors

      Since the job has the SCM information built directly into the pipeline job, shouldn't onNotifyCommit properly find and notify the new job without needing execution?

      Attachments

        Activity

          angrygami Angry Gami added a comment -

          I wrote a test for workflow-job project that shows the case and fix for it:

          pom.xml

          diff --git a/pom.xml b/pom.xml
          index b9b8e64..f255e37 100644
          --- a/pom.xml
          +++ b/pom.xml
          @@ -93,13 +93,13 @@
                       <!-- Satisfy upper bound dependencies -->
                       <groupId>org.jenkins-ci.plugins</groupId>
                       <artifactId>script-security</artifactId>
          -            <version>1.62</version>
          +            <version>1.63</version>
                       <scope>test</scope>
                   </dependency>
                   <dependency>
                       <groupId>org.jenkins-ci.plugins.workflow</groupId>
                       <artifactId>workflow-cps</artifactId>
          -            <version>2.74</version>
          +            <version>2.76</version>
                       <scope>test</scope>
                   </dependency>
                   <dependency>
          

          WorkflowJobTest.java

          diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java
          index 53b27de..b32130f 100644
          --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java
          +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java
          @@ -69,6 +69,15 @@ public class WorkflowJobTest {
                   j.assertLogContains("second version", b2);
               }
           
          +    @Issue("JENKINS-38669")
          +    @Test public void nonEmptySCMListForGitSCMJobBeforeBuild() throws Exception {
          +        WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
          +        CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitSCM("I don't care"), "Jenkinsfile");
          +        assertEquals("Expecting one SCM for definition", 1, def.getSCMs().size());
          +        p.setDefinition(def);
          +        assertEquals("Expecting one SCM", 1, p.getSCMs().size());
          +    }
          +
               @Test
               public void addAction() throws Exception {
                   WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
          

          Though I'm not sure this is good for master branch, I was working from repo tag 'workflow-job-2.36'.

          angrygami Angry Gami added a comment - I wrote a test for workflow-job project that shows the case and fix for it: pom.xml diff --git a/pom.xml b/pom.xml index b9b8e64..f255e37 100644 --- a/pom.xml +++ b/pom.xml @@ -93,13 +93,13 @@ <!-- Satisfy upper bound dependencies --> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>script-security</artifactId> - <version>1.62</version> + <version>1.63</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jenkins-ci.plugins.workflow</groupId> <artifactId>workflow-cps</artifactId> - <version>2.74</version> + <version>2.76</version> <scope>test</scope> </dependency> <dependency> WorkflowJobTest.java diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java index 53b27de..b32130f 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java @@ -69,6 +69,15 @@ public class WorkflowJobTest { j.assertLogContains( "second version" , b2); } + @Issue( "JENKINS-38669" ) + @Test public void nonEmptySCMListForGitSCMJobBeforeBuild() throws Exception { + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p" ); + CpsScmFlowDefinition def = new CpsScmFlowDefinition( new GitSCM( "I don't care" ), "Jenkinsfile" ); + assertEquals( "Expecting one SCM for definition" , 1, def.getSCMs().size()); + p.setDefinition(def); + assertEquals( "Expecting one SCM" , 1, p.getSCMs().size()); + } + @Test public void addAction() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p" ); Though I'm not sure this is good for master branch, I was working from repo tag 'workflow-job-2.36'.
          markewaite Mark Waite added a comment -

          Yes, please submit a pull request with your proposal. The "how to use incrementals" blog post from Jesse Glick and the Jenkins incrementals tools README are two good references that should allow you to more easily develop changes across multiple plugins.

          I'm not expert enough in the details of the pipeline flow definition to comment on the viability of the change you're proposing. The pipeline maintainers will be much better suited to assess the impact of the proposed change than I am. They are most likely to prefer a pull request as the way to review the idea.

          markewaite Mark Waite added a comment - Yes, please submit a pull request with your proposal. The " how to use incrementals " blog post from Jesse Glick and the Jenkins incrementals tools README are two good references that should allow you to more easily develop changes across multiple plugins. I'm not expert enough in the details of the pipeline flow definition to comment on the viability of the change you're proposing. The pipeline maintainers will be much better suited to assess the impact of the proposed change than I am. They are most likely to prefer a pull request as the way to review the idea.
          dnusbaum Devin Nusbaum added a comment -

          angrygami Thanks for looking into this. Note that WorkflowJob.getSCMs includes SCMs for things like shared libraries or uses of the checkout step from inside of the Pipeline, so IIUC changes to any of those SCMs will trigger a build after the first successful build has completed (and for one extra build even if the Pipeline was changed to no longer use those SCMs). The proposed API would only work for the SCM used for the Jenkinsfile, and only for CpsScmFlowDefinition, which is still better than today, but I think we'd want to make sure to be very clear about what would and would not work in the changelog and any documentation. CC bitwiseman in case he has any thoughts.

          dnusbaum Devin Nusbaum added a comment - angrygami Thanks for looking into this. Note that WorkflowJob.getSCMs includes SCMs for things like shared libraries or uses of the checkout step from inside of the Pipeline, so IIUC changes to any of those SCMs will trigger a build after the first successful build has completed (and for one extra build even if the Pipeline was changed to no longer use those SCMs). The proposed API would only work for the SCM used for the Jenkinsfile, and only for CpsScmFlowDefinition , which is still better than today, but I think we'd want to make sure to be very clear about what would and would not work in the changelog and any documentation. CC bitwiseman in case he has any thoughts.
          angrygami Angry Gami added a comment -

          The proposed API would only work for the SCM used for the Jenkinsfile, and only for CpsScmFlowDefinition
          This was my intention. I understand that some FlowDefintion subclasses are not using scm at all. I was annoyed that one that definitely do don't work as expected. I've seen your comment on github and will make other PRs as soon as I have time Thanks.
           

           

          angrygami Angry Gami added a comment - The proposed API would only work for the SCM used for the Jenkinsfile, and only for CpsScmFlowDefinition This was my intention. I understand that some FlowDefintion subclasses are not using scm at all. I was annoyed that one that definitely do don't work as expected. I've seen your comment on github and will make other PRs as soon as I have time Thanks.    
          angrygami Angry Gami added a comment - - edited

          Ok, all PRs are now done. Though https://github.com/jenkinsci/workflow-job-plugin/pull/147 fails and I don't understand why. Please 0u812 could you take a look?

          angrygami Angry Gami added a comment - - edited Ok, all PRs are now done. Though https://github.com/jenkinsci/workflow-job-plugin/pull/147 fails and I don't understand why. Please 0u812 could you take a look?

          People

            angrygami Angry Gami
            dgomez Dayton Gomez
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: