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

Add EnvironmentVar feature to allow people access to Remote job

      The Parameterized Build plugin give people access to the following environment variables:

      • - LAST_TRIGGERED_JOB_NAME="Last project started"
      • - TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered"
      • - TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
      • - TRIGGERED_BUILD_NUMBERS_<project name>="Comma separated list of build numbers triggered"
      • - TRIGGERED_BUILD_RESULT_<project name>="Last triggered build result of project"
      • - TRIGGERED_BUILD_RESULT_<project name>RUN<build number>="Result of triggered build for build number"
      • - TRIGGERED_BUILD_RUN_COUNT_project name>="Number of builds triggered for the project"

      It would be good if the Remote Parameterised Plugin could give people access to at least:

      • - TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered"

      As we are trying to download artifacts using the lastSuccessul link, and this is failing when another job is kicked off on the remote job.

      I have a POC working if you'd like the code - needs Unit Tests though (has only been bench tested).

          [JENKINS-22384] Add EnvironmentVar feature to allow people access to Remote job

          Tim Brown added a comment -

          I have added this functionality to the following branch:
          https://github.com/timbrown5/parameterized-remote-trigger-plugin/tree/JENKINS-22384-Add-EnvVars

          We are using this locally, please let me know if you'd like me to submit a pull request.

          Note: This branch also has a workaround for some local networking issues we are having. We are finding that sometimes a connection drops and this makes the plugin drop out too early. To workaround this I have added a connectionRetry section to sendHTTPCall (in the catch IOException) that retries the call x amount of times before failing - suing recursion. This is hard coded to 5, but could be available to be configured via jelly input (although we've only ever seen it retry once at a time).

          Tim Brown added a comment - I have added this functionality to the following branch: https://github.com/timbrown5/parameterized-remote-trigger-plugin/tree/JENKINS-22384-Add-EnvVars We are using this locally, please let me know if you'd like me to submit a pull request. Note: This branch also has a workaround for some local networking issues we are having. We are finding that sometimes a connection drops and this makes the plugin drop out too early. To workaround this I have added a connectionRetry section to sendHTTPCall (in the catch IOException) that retries the call x amount of times before failing - suing recursion. This is hard coded to 5, but could be available to be configured via jelly input (although we've only ever seen it retry once at a time).

          Tim Brown added a comment - - edited

          Added this code to the master branch in my fork:

          I have added all of the below EnvVars (they all get added in one method, so it should be easy to extend/change in the future):

          • LAST_TRIGGERED_JOB_NAME="Last project started"
          • TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered"
          • TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
          • TRIGGERED_BUILD_NUMBERS_<project name>="Comma separated list of build numbers triggered"
          • TRIGGERED_BUILD_RESULT_<project name>="Last triggered build result of project"
          • TRIGGERED_BUILD_RESULT_<project name>RUN<build number>="Result of triggered build for build number" <-- I have implemented this one has underscore near the run, e.g.: TRIGGERED_BUILD_RESULT_My_Project_RUN_12 instead of: TRIGGERED_BUILD_RESULT_My_ProjectRUN12. According to the Parameterized Build plug-in documentation this is wrong, but I think this is easier to use. Can change be changed easily if required.
          • TRIGGERED_BUILD_RUN_COUNT_project name>="Number of builds triggered for the project"

          Tim Brown added a comment - - edited Added this code to the master branch in my fork: I have added all of the below EnvVars (they all get added in one method, so it should be easy to extend/change in the future): LAST_TRIGGERED_JOB_NAME="Last project started" TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered" TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects" TRIGGERED_BUILD_NUMBERS_<project name>="Comma separated list of build numbers triggered" TRIGGERED_BUILD_RESULT_<project name>="Last triggered build result of project" TRIGGERED_BUILD_RESULT_<project name> RUN <build number>="Result of triggered build for build number" <-- I have implemented this one has underscore near the run, e.g.: TRIGGERED_BUILD_RESULT_My_Project_RUN_12 instead of: TRIGGERED_BUILD_RESULT_My_ProjectRUN12. According to the Parameterized Build plug-in documentation this is wrong, but I think this is easier to use. Can change be changed easily if required. TRIGGERED_BUILD_RUN_COUNT_project name>="Number of builds triggered for the project"

          Maurice W. added a comment -

          Tim, when you think it's ready please go ahead an issue PR.
          And this entire plugin is lacking unit tests

          Maurice W. added a comment - Tim, when you think it's ready please go ahead an issue PR. And this entire plugin is lacking unit tests

          Tim Brown added a comment - - edited

          I think it would be best to fix the major issues and add UTs before we try and put this in (as it could cause a lot of confusion).

          I can create another branch here and submit some of the UTs I have done - at least it will be something to build on .

          Tim Brown added a comment - - edited I think it would be best to fix the major issues and add UTs before we try and put this in (as it could cause a lot of confusion). I can create another branch here and submit some of the UTs I have done - at least it will be something to build on .

          Tim Brown added a comment -

          After revisiting this today I released that using the same EnvVars as the Trigger Build building will lead to conflicts (we will be overwriting each other's Env Vars). Renaming the Variables to:
          •- LAST_REMOTE_TRIGGERED_JOB_NAME="Last project started"
          •- REMOTE_TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered"
          •- REMOTE_TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
          •- REMOTE_TRIGGERED_BUILD_NUMBERS_<project name>="Comma separated list of build numbers triggered"
          •- REMOTE_TRIGGERED_BUILD_RESULT_<project name>="Last triggered build result of project"
          •- REMOTE_TRIGGERED_BUILD_RESULT_<project name>RUN<build number>="Result of triggered build for build number"
          •- REMOTE_TRIGGERED_BUILD_RUN_COUNT_project name>="Number of builds triggered for the project"

          Tim Brown added a comment - After revisiting this today I released that using the same EnvVars as the Trigger Build building will lead to conflicts (we will be overwriting each other's Env Vars). Renaming the Variables to: •- LAST_REMOTE_TRIGGERED_JOB_NAME="Last project started" •- REMOTE_TRIGGERED_BUILD_NUMBER_<project name>="Last build number triggered" •- REMOTE_TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects" •- REMOTE_TRIGGERED_BUILD_NUMBERS_<project name>="Comma separated list of build numbers triggered" •- REMOTE_TRIGGERED_BUILD_RESULT_<project name>="Last triggered build result of project" •- REMOTE_TRIGGERED_BUILD_RESULT_<project name>RUN<build number>="Result of triggered build for build number" •- REMOTE_TRIGGERED_BUILD_RUN_COUNT_project name>="Number of builds triggered for the project"

          Thanks Tim, this is a very useful feature. I have tested it and it works well.
          It would be nice to see it in official version.

          Jerome HOURQUEBIE added a comment - Thanks Tim, this is a very useful feature. I have tested it and it works well. It would be nice to see it in official version.

            canuck1987 Tim Brown
            canuck1987 Tim Brown
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: