• Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • core

      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?

          [JENKINS-25164] Provide a short $JOB_NAME inside a folder

          Dirk Kuypers created issue -

          Daniel Beck added a comment -

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

          Daniel Beck added a comment - Folders can be nested. Wouldn't FOLDER_NAME then still have this problem?

          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...

          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...

          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.

          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 .

          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...

          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...
          Dirk Kuypers made changes -
          Component/s New: core [ 15593 ]
          Component/s Original: cloudbees-folder [ 18137 ]
          Labels New: folders

          Jesse Glick added a comment -

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

          Jesse Glick added a comment - Well maybe it was not already filed. Perhaps was just discussed somewhere else.

          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))
          }
          

          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)) }

          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.

          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.
          Jesse Glick made changes -
          Component/s New: cloudbees-folder-plugin [ 18137 ]
          Component/s Original: core [ 15593 ]
          Assignee Original: Jesse Glick [ jglick ]
          Labels Original: folders
          Priority Original: Minor [ 4 ] New: Major [ 3 ]

            fbelzunc Félix Belzunce Arcos
            bruce Dirk Kuypers
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: