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

Pipeline Multibranch - Add the possibility to use a Jenkinsfile from other SCM

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • None

      We need to have different Declarative Pipelines per roles/definitions  (role: developers; role: DevOps)

      Declarative Jenkinsfile for developers: in maven-java project is Jenkinsfile

      Declarative Jenkinsfile for DevOps: in generic devops project

      In Scan Multibranch Pipeline:

      *Case 1:

      -Branch Sources: maven-java project http://svn/VersionesJenkins20

      -Build Configuration by Jenkinsfile Script Path ../../Jenkins/Pipeline/trunk/Jenkinsfile

      Scan Multibranch Pipeline Log ERROR:

      ERROR: [Mon Jul 03 14:18:06 ART 2017] Could not fetch branches from source 90b1b9e5-a010-4b1a-a717-2a2b51b9e42e
      java.io.IOException: org.tmatesoft.svn.core.SVNException: svn: E125002: URL 'http://svn/VersionesJenkins20/branches/VersionesJenkins20-sinFileJenkins/../..' contains .. element

      *Case 2:

      -Branch Sources: maven-java project http://svn/VersionesJenkins20 + generic devops project http://svn/Jenkins/Pipeline/trunk/

      -Build Configuration by Jenkinsfile Script Path Jenkinsfile

      PROBLEM: Jenkins runs Jenkinsfile from maven-java project ignoring generic devops project

       

      POSSIBLE SOLUTION:

      -Allow to define shared workspace with Jenkins file

      -Allow to define scm svn to the declarative devops jenkinsfile

       

          [JENKINS-45273] Pipeline Multibranch - Add the possibility to use a Jenkinsfile from other SCM

          I don't like having to put our Jenkinsfile into every single repository. And somehow hope that all of them get all the changes to it.

          Some of this can be worked around by using shared pipeline libraries so the Jenkinsfile becomes small. But the general pipeline project have the option to get the 'Pipeline script from a SCM', why not the multibranch pipeline?

          Hack Kampbjørn added a comment - I don't like having to put our Jenkinsfile into every single repository. And somehow hope that all of them get all the changes to it. Some of this can be worked around by using shared pipeline libraries so the Jenkinsfile becomes small. But the general pipeline project have the option to get the 'Pipeline script from a SCM', why not the multibranch pipeline?

          Hack Kampbjørn I found a workaround for multibranch pipeline using pipeline-multibranch-defaults-plugin

          Install plugin https://plugins.jenkins.io/pipeline-multibranch-defaults and https://plugins.jenkins.io/config-file-provider

          In Admin Jenkins -> Managed Files

          Add a new Config (forJenkinsfile)
          Select Groovy File
          ID: Jenkinsfile
          Press Submit
          Name: MyJenkinsfile
          Comment: My DefaultJenkinsfile
          In Content: [shared-pipeline-name]
          Press Submit

           

          Then in your multibranch pipeline 

          Build Configuration: Mode: by default Jenkinsfile 

           

          That's it! 

           

           

           

           

          Mariela Daventini added a comment - Hack Kampbjørn I found a workaround for multibranch pipeline using pipeline-multibranch-defaults-plugin Install plugin https://plugins.jenkins.io/pipeline-multibranch-defaults  and https://plugins.jenkins.io/config-file-provider In Admin Jenkins -> Managed Files Add a new Config (forJenkinsfile) Select Groovy File ID: Jenkinsfile Press Submit Name: MyJenkinsfile Comment: My DefaultJenkinsfile In Content: [shared-pipeline-name] Press Submit   Then in your multibranch pipeline  Build Configuration: Mode: by default Jenkinsfile    That's it!         

          Sam Van Oort added a comment -

          It's a bit hard to follow the discussion here, but sounds like there is actually a way to accomplish this (albeit a bit awkwardly), and I know of at least one proprietary Jenkins extension offering what it sounds like this does, so am adjusting the priority downward a bit.

          Please feel free to amend the title/description to more clearly explain what specifically needed here and why it's critical if you think this should be a critical-priority improvement.

          Sam Van Oort added a comment - It's a bit hard to follow the discussion here, but sounds like there is actually a way to accomplish this (albeit a bit awkwardly), and I know of at least one proprietary Jenkins extension offering what it sounds like this does, so am adjusting the priority downward a bit. Please feel free to amend the title/description to more clearly explain what specifically needed here and why it's critical if you think this should be a critical-priority improvement.

          I reported this one! But now we are using shared libraries, so Jenkinsfile only contains the call to the shared library

          Example:

          DefaultJenkinsPipeline()

           

          Mariela Daventini added a comment - I reported this one! But now we are using shared libraries, so Jenkinsfile only contains the call to the shared library Example: DefaultJenkinsPipeline()  

          Sam Van Oort added a comment -

          mdaventini Ah! Okay, excellent, best possible outcome. Does that mean I can go ahead and close this one out?

          Sam Van Oort added a comment - mdaventini Ah! Okay, excellent, best possible outcome. Does that mean I can go ahead and close this one out?

          I think so svanoort

          If any voter needs support, I really recomend using shared libraries!

          Mariela Daventini added a comment - I think so svanoort !  If any voter needs support, I really recomend using shared libraries!

          Mark R added a comment -

          Use case: I have a forked opensource repo that I want to make changes to but don't want to pollute with a Jenkinsfile to build with internally. The Jenkinsfile must thus be in a different repository (without playing games in git to "hide" the Jenkinsfile commit(s)). If however I put it in a different repository I loose the ability to have bitbucket trigger the job on push to automatically build branches - right now it will only detect changes from the repository that has the Jenkinsfile which really won't change.

          Mark R added a comment - Use case: I have a forked opensource repo that I want to make changes to but don't want to pollute with a Jenkinsfile to build with internally. The Jenkinsfile must thus be in a different repository (without playing games in git to "hide" the Jenkinsfile commit(s)). If however I put it in a different repository I loose the ability to have bitbucket trigger the job on push to automatically build branches - right now it will only detect changes from the repository that has the Jenkinsfile which really won't change.

          Jesse Glick added a comment -

          mrichar2 you can use the Pipeline Multibranch Defaults plugin for this, or if you are a CloudBees customer there is a “custom marker file” feature which is more flexible still.

          Jesse Glick added a comment - mrichar2 you can use the Pipeline Multibranch Defaults plugin for this, or if you are a CloudBees customer there is a “custom marker file” feature which is more flexible still.

          Devin Nusbaum added a comment -

          I am closing this ticket. As far as I know there are two open source plugins that support this use case directly:

          As Jesse mentioned, CloudBees also implemented a feature like this for CloudBees customers, see the documentation here.

          If those plugins do not have the features you want, I would open an RFE against the one you want to use, describing your use case and explaining why the current functionality of the plugin is not adequate.

          Devin Nusbaum added a comment - I am closing this ticket. As far as I know there are two open source plugins that support this use case directly: Pipeline: Multibranch with defaults Remote File Plugin (CC aytuncbeken , any thoughts about changing the display name of the plugin to something like "Pipeline Multibranch Remote Jenkinsfile Plugin" for clarity and so that users are more likely to find it when searching?) As Jesse mentioned, CloudBees also implemented a feature like this for CloudBees customers, see the documentation here . If those plugins do not have the features you want, I would open an RFE against the one you want to use, describing your use case and explaining why the current functionality of the plugin is not adequate.

          Aytunc BEKEN added a comment - - edited

          dnusbaum I agree with you, I will try to change the plugin name. Thanks for the suggestion.

          Aytunc BEKEN added a comment - - edited dnusbaum I agree with you, I will try to change the plugin name. Thanks for the suggestion.

            Unassigned Unassigned
            mdaventini Mariela Daventini
            Votes:
            8 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: