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

Allow the workflowLibs.git to be hosted someplace else

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Minor Minor
    • pipeline
    • None
    • Jenkins-Version: 1.651.1
      workflow-cps-global-lib: 2.0

      We are using GitHub Enterprise and the GitHub Organization Folders for everything.

      Well, everything except workflowLibs.git.

      We would like to be able to use the same workflow for contributing, managing, etc. workflowLibs.git code that we use for everything else.

      In addition, we plan on having (roughly) one Jenkins per Organization, but would like to share (some? all?) of the workflowLibs.git across Jenkinses.

      If this isn't done directly (i.e. just replace the built-in git repository with an external one) then some guidance or suggested workflows would be nice.

      Some questions:

      • Is ${JENKINS_HOME/workflow-libs}} the actual repository? Is there a bare repository someplace I'm not seeing?
      • Is there a Jenkinsfile way to push changes into workflowLibs.git?
      • Can I just add a new remote to ${JENKINS_HOME}/workflow-libs and do a git pull --mirror?

          [JENKINS-34476] Allow the workflowLibs.git to be hosted someplace else

          Jesse Glick added a comment -

          Well-known RFE, larger issue. There is a Remote Loader plugin but it does not cover quite the same functionality.

          Jesse Glick added a comment - Well-known RFE, larger issue. There is a Remote Loader plugin but it does not cover quite the same functionality.

          Here is how I manage to get this functionality, though we are using Stash instead of GitHub:

          • Create workflow-libs repo in SCM
          • Navigate to JENKINS_HOME/workflow-libs directory on jenkins server
          • Do
            git clone YOUR_REPO_URL 
            • The key here is to make sure the repo is cloned right into the directory, not into a sub directory.
          • Create a freestyle jenkins job and point it to your workflow-libs repo
          • Add "Execute Shell" step to navigate to the JENKINS_HOME/workflow-libs directory and execute a git pull
            • e.g
               cd ../../workflow-libs
              git pull 
          • If your GitHub repo uses web-hooks, configure it to notify jenkins when the repo has been committed to
          • Configure the jenkins job to build when notified of a commit to the repo

          Some of these steps may be a little different for GitHub as I am not familiar with the web-hook functionality there. I assume something similar could be achieved by a polling schedule from within the jenkins job.

          This has worked well for us, especially in making UPDATES to global scripts. The one issue we have is that when committing a NEW script to the repo. After the push to the repo and the jenkins job has run to update the workflow-libs repo on the jenkins server, the new global script won't be available until after a jenkins restart. Before a restart you'll get a "Global Script Not Found" or similar error.

          Hope this helps

          Michael Scharp added a comment - Here is how I manage to get this functionality, though we are using Stash instead of GitHub: Create workflow-libs repo in SCM Navigate to JENKINS_HOME/workflow-libs directory on jenkins server Do git clone YOUR_REPO_URL The key here is to make sure the repo is cloned right into the directory, not into a sub directory. Create a freestyle jenkins job and point it to your workflow-libs repo Add "Execute Shell" step to navigate to the JENKINS_HOME/workflow-libs directory and execute a git pull e.g cd ../../workflow-libs git pull If your GitHub repo uses web-hooks, configure it to notify jenkins when the repo has been committed to Configure the jenkins job to build when notified of a commit to the repo Some of these steps may be a little different for GitHub as I am not familiar with the web-hook functionality there. I assume something similar could be achieved by a polling schedule from within the jenkins job. This has worked well for us, especially in making UPDATES to global scripts. The one issue we have is that when committing a NEW script to the repo. After the push to the repo and the jenkins job has run to update the workflow-libs repo on the jenkins server, the new global script won't be available until after a jenkins restart. Before a restart you'll get a "Global Script Not Found" or similar error. Hope this helps

          Matt Traynham added a comment -

          mscharp I'm looking to do the same and find the https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin somewhat lacking. Curious as why you have to restart? Does the original workflowLib.git have some commit hook that notifies Jenkins that the lib has been updated?

          Matt Traynham added a comment - mscharp I'm looking to do the same and find the https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin somewhat lacking. Curious as why you have to restart? Does the original workflowLib.git have some commit hook that notifies Jenkins that the lib has been updated?

            jglick Jesse Glick
            docwhat Christian Höltje
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: