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

Provide a short $JOB_NAME inside a folder

    Details

    • Similar Issues:

      Description

      We are using $JOB_NAME a lot to automatically create names für ClearCase views in our jobs. This looks like

      ${USER_NAME}${COMPUTERNAME}${JOB_NAME} for the view tag and
      ${JOB_NAME} for the view name.

      Additionaly we ha a small managed script to automatically create a build tag:
      echo %BUILD_TAG% > %CLEARCASE_VIEWPATH%%JOB_NAME%-build.tag

      When a Job is now moved into a folder the JOB-NAME is "foldername/jobname" which is longer and contains a slash causing real pain on windows.

      I don't know if someone is relying on JOB_NAME containing the folder name and the slash, but would it be possible to separate this into two variables like FOLDER_NAME and (SHORT_)JOB_NAME?

        Attachments

          Activity

          bruce Dirk Kuypers created issue -
          Hide
          danielbeck Daniel Beck added a comment -

          Folders can be nested. Wouldn't FOLDER_NAME then still have this problem?

          Show
          danielbeck Daniel Beck added a comment - Folders can be nested. Wouldn't FOLDER_NAME then still have this problem?
          Hide
          bruce Dirk Kuypers added a comment - - edited

          Good point Daniel. So this seems to be not that easy. At least some sort of SHORT_JOB_NAME or PROJECT_NAME would ease my life a lot.

          With nested folders I would get really long job names which will cause a long path to my ClearCase view root alone. And I already ran into problems with Windows paths being longer than ~250 characters without using folders.:-/ The same applies to our MSTest unit test projects where I use $JOB_NAME quite often because I generate the tests via groovy and job-dsl...

          Show
          bruce Dirk Kuypers added a comment - - edited Good point Daniel. So this seems to be not that easy. At least some sort of SHORT_JOB_NAME or PROJECT_NAME would ease my life a lot. With nested folders I would get really long job names which will cause a long path to my ClearCase view root alone. And I already ran into problems with Windows paths being longer than ~250 characters without using folders.:-/ The same applies to our MSTest unit test projects where I use $JOB_NAME quite often because I generate the tests via groovy and job-dsl...
          Hide
          jglick Jesse Glick added a comment -

          This is a duplicate of something but do not have time to look it up now. Anyway component should be core, with label folders.

          Show
          jglick Jesse Glick added a comment - This is a duplicate of something but do not have time to look it up now. Anyway component should be core , with label folders .
          Hide
          bruce Dirk Kuypers added a comment -

          Thanks Jesse, I changed the component and added the label but I am not able to find the related Issue. Too dumb to search...

          Show
          bruce Dirk Kuypers added a comment - Thanks Jesse, I changed the component and added the label but I am not able to find the related Issue. Too dumb to search...
          bruce Dirk Kuypers made changes -
          Field Original Value New Value
          Labels folders
          Component/s core [ 15593 ]
          Component/s cloudbees-folder [ 18137 ]
          Hide
          jglick Jesse Glick added a comment -

          Well maybe it was not already filed. Perhaps was just discussed somewhere else.

          Show
          jglick Jesse Glick added a comment - Well maybe it was not already filed. Perhaps was just discussed somewhere else.
          Hide
          walterk82 Walter Kacynski added a comment -

          Groovy Script that can be used. This will pull only the last portion of the job name and create a new environment variable.

          JOBNAME = build.getEnvironment(null)["JOB_NAME"]
          def match = JOBNAME =~ /.*\/(.*)/
          if (match) { 
          	e = new hudson.EnvVars()
          	e.put('SHORT_JOB_NAME', match[0][1])
          	build.environments.add(hudson.model.Environment.create(e))
          }
          
          Show
          walterk82 Walter Kacynski added a comment - Groovy Script that can be used. This will pull only the last portion of the job name and create a new environment variable. JOBNAME = build.getEnvironment( null )[ "JOB_NAME" ] def match = JOBNAME =~ /.*\/(.*)/ if (match) { e = new hudson.EnvVars() e.put( 'SHORT_JOB_NAME' , match[0][1]) build.environments.add(hudson.model.Environment.create(e)) }
          Hide
          jglick Jesse Glick added a comment -

          Workaround inside (Unix) shell steps is

          ${JOB_NAME##*/}
          

          But not available in other contexts.

          Could be done easily as an EnvironmentContributor (even added to top-level jobs for the sake of consistency). Do not forget the buildEnv.jelly for documentation.

          Show
          jglick Jesse Glick added a comment - Workaround inside (Unix) shell steps is ${JOB_NAME##*/} But not available in other contexts. Could be done easily as an EnvironmentContributor (even added to top-level jobs for the sake of consistency). Do not forget the buildEnv.jelly for documentation.
          jglick Jesse Glick made changes -
          Component/s cloudbees-folder-plugin [ 18137 ]
          Component/s core [ 15593 ]
          Assignee Jesse Glick [ jglick ]
          Priority Minor [ 4 ] Major [ 3 ]
          Labels folders
          Hide
          allan_burdajewicz Allan BURDAJEWICZ added a comment -

          The EnvInject plugin gives access to currentJob instance and therefore it is possible to inject the "short" job name like this:

          return ['ITEM_NAME': currentJob.getName()]
          
          Show
          allan_burdajewicz Allan BURDAJEWICZ added a comment - The EnvInject plugin gives access to currentJob instance and therefore it is possible to inject the "short" job name like this: return [ 'ITEM_NAME' : currentJob.getName()]
          fbelzunc Félix Belzunce Arcos made changes -
          Assignee Félix Belzunce Arcos [ fbelzunc ]
          fbelzunc Félix Belzunce Arcos made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          fbelzunc Félix Belzunce Arcos made changes -
          Component/s core [ 15593 ]
          Component/s cloudbees-folder-plugin [ 18137 ]
          fbelzunc Félix Belzunce Arcos made changes -
          Labels folders
          Hide
          teilo James Nord added a comment -

          It should be trivial to implement this in a plugin. see buildtagfixer for an approach that fixed the BUILD_TAG environment variable to contain the full job name when folders where first introduced.

          Show
          teilo James Nord added a comment - It should be trivial to implement this in a plugin. see buildtagfixer for an approach that fixed the BUILD_TAG environment variable to contain the full job name when folders where first introduced.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Felix Belzunce Arcos
          Path:
          core/src/main/java/hudson/model/Job.java
          core/src/main/resources/jenkins/model/CoreEnvironmentContributor/buildEnv.groovy
          core/src/main/resources/jenkins/model/CoreEnvironmentContributor/buildEnv.properties
          http://jenkins-ci.org/commit/jenkins/4bab3630efcc2fa331db2989e321d9af1b8cdc1c
          Log:
          [FIXED JENKINS-25164] Add JOB_BASE_NAME env var (#2321)

          • Delete strip off
          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Felix Belzunce Arcos Path: core/src/main/java/hudson/model/Job.java core/src/main/resources/jenkins/model/CoreEnvironmentContributor/buildEnv.groovy core/src/main/resources/jenkins/model/CoreEnvironmentContributor/buildEnv.properties http://jenkins-ci.org/commit/jenkins/4bab3630efcc2fa331db2989e321d9af1b8cdc1c Log: [FIXED JENKINS-25164] Add JOB_BASE_NAME env var (#2321) JENKINS-25164 Add SHORT_JOB_NAME env var Delete strip off JENKINS-25164 Change SHORT_JOB_NAME for LEAF_JOB_NAME JENKINS-25164 Change LEAF_JOB_NAME for JOB_BASE_NAME
          scm_issue_link SCM/JIRA link daemon made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Released as Jenkins-2.4

          Show
          oleg_nenashev Oleg Nenashev added a comment - Released as Jenkins-2.4
          oleg_nenashev Oleg Nenashev made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Hide
          djviking Sverre Moe added a comment -

          Not sure if it is intentional
          With Jenkins pipeline the JOB_BASE_NAME is same as BRANCH_NAME instead of the actual project name.
          BRANCH_NAME=master
          JOB_NAME=projectA/master
          JOB_BASE_NAME=master

          The value for JOB_BASE_NAME should be in this case projectA.

          Show
          djviking Sverre Moe added a comment - Not sure if it is intentional With Jenkins pipeline the JOB_BASE_NAME is same as BRANCH_NAME instead of the actual project name. BRANCH_NAME=master JOB_NAME=projectA/master JOB_BASE_NAME=master The value for JOB_BASE_NAME should be in this case projectA.
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 159073 ] JNJira + In-Review [ 208134 ]

            People

            • Assignee:
              fbelzunc Félix Belzunce Arcos
              Reporter:
              bruce Dirk Kuypers
            • Votes:
              2 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: