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

Add note to env-vars.html so user knows that Environment variables configuration is requried to export JENKINS_URL, JOB_URL, BUILD_URL

    Details

    • Similar Issues:

      Description

      An Execute shell build step with simple command `env` shows that none of the *_URL environment variables are being imported to the shell.

      Scripts that access the Jenkins REST API rely on these vars to execute.

      E.g. output of `env` step on 1.495

      BUILD_CAUSE_USERIDCAUSE=true
      HUDSON_SERVER_COOKIE=62a4ddfd88c783b78b6ae030cb9d0617
      SHELL=/bin/bash
      TMPDIR=/var/folders/zv/6gwf54fj3c791gjxcddqp9t400007c/T/
      BUILD_TAG=jenkins-ios-app_master-17
      WORKSPACE=/Users/Shared/Jenkins/Home/jobs/ios-app_master/workspace
      com.apple.java.jvmTask=CommandLine.java.java.java.java.java.java
      USER=jenkins
      __CF_USER_TEXT_ENCODING=0xEC:0:0
      GIT_COMMIT=925e5ce56d7b6f0b67015131f8dd9d85e9c1168b
      JENKINS_HOME=/Users/Shared/Jenkins/Home
      PATH=/usr/bin:/bin:/usr/sbin:/sbin
      PWD=/Users/Shared/Jenkins/Home/jobs/ios-app_master/workspace
      JOB_NAME=ios-app_master
      JAVA_MAIN_CLASS_8793=Main
      com.apple.java.jvmMode=client
      BUILD_CAUSE=USERIDCAUSE
      BUILD_ID=2012-12-29_10-31-47
      HOME=/Users/Shared/Jenkins
      SHLVL=1
      GIT_BRANCH=origin/master
      JENKINS_SERVER_COOKIE=62a4ddfd88c783b78b6ae030cb9d0617
      EXECUTOR_NUMBER=0
      NODE_LABELS=master
      LOGNAME=jenkins
      HUDSON_HOME=/Users/Shared/Jenkins/Home
      NODE_NAME=master
      BUILD_NUMBER=17
      HUDSON_COOKIE=fadc3c90-aca8-4b58-8850-5aded45d1348
      JAVA_ARCH=x86_64
      SECURITYSESSIONID=186d2
      _=/usr/bin/env

        Attachments

          Issue Links

            Activity

            Hide
            sti Sami Tikka added a comment -

            There seems to be the same underlying root cause.

            Show
            sti Sami Tikka added a comment - There seems to be the same underlying root cause.
            Hide
            sti Sami Tikka added a comment -

            Sorry for being so thick-headed.. I only now understood what the problem is and verified it myself. Set up a new Jenkins (1.502), set up a job that runs "env" and build it. Then go to the global configuration, click Save. Then build the job again. Compare the output from env command:

            The environment variables BUILD_URL, JOB_URL, JENKINS_URL and HUDSON_URL are missing from the first run and only appear after you have visited global configuration AND clicked the Save button. It is not enough to visit the global configuration. You have to click the Save button.

            This really is a bug. Not a huge bug and there is a good workaround. I'm not sure if anyone would set up a real Jenkins instance without even once visiting the global configuration... but it is a bug anyway.

            Show
            sti Sami Tikka added a comment - Sorry for being so thick-headed.. I only now understood what the problem is and verified it myself. Set up a new Jenkins (1.502), set up a job that runs "env" and build it. Then go to the global configuration, click Save. Then build the job again. Compare the output from env command: The environment variables BUILD_URL, JOB_URL, JENKINS_URL and HUDSON_URL are missing from the first run and only appear after you have visited global configuration AND clicked the Save button. It is not enough to visit the global configuration. You have to click the Save button. This really is a bug. Not a huge bug and there is a good workaround. I'm not sure if anyone would set up a real Jenkins instance without even once visiting the global configuration... but it is a bug anyway.
            Hide
            mkollaro Martina Kollarova added a comment -

            Is there some workaround for this that doesn't require human intervention? I'm writing a script that automatically installs and configures Jenkins, then uses jenkins-job-builder to create the jobs. I'd like this to work without the user having to click around, but I need to have JENKINS_URL set for some of the jobs to work.

            Show
            mkollaro Martina Kollarova added a comment - Is there some workaround for this that doesn't require human intervention? I'm writing a script that automatically installs and configures Jenkins, then uses jenkins-job-builder to create the jobs. I'd like this to work without the user having to click around, but I need to have JENKINS_URL set for some of the jobs to work.
            Hide
            adamtheturtle Adam Dangoor added a comment -

            We are in the same position as Martina Kollarova two years later! We are likely going to use PhantomJS to click the button.

            Show
            adamtheturtle Adam Dangoor added a comment - We are in the same position as Martina Kollarova two years later! We are likely going to use PhantomJS to click the button.
            Hide
            stickycode Michael McCallum added a comment -

            An init.d.groovy script like so will set your url and allow jobs to access the JOB_URL OOTB

            import jenkins.model.JenkinsLocationConfiguration

            location = JenkinsLocationConfiguration.get()
            location.setUrl('https://jenkins.example.com')
            location.setAdminAddress('jenkins@example.com');
            location.save()

            Show
            stickycode Michael McCallum added a comment - An init.d.groovy script like so will set your url and allow jobs to access the JOB_URL OOTB import jenkins.model.JenkinsLocationConfiguration location = JenkinsLocationConfiguration.get() location.setUrl('https://jenkins.example.com') location.setAdminAddress('jenkins@example.com'); location.save()

              People

              • Assignee:
                richscze nobody
                Reporter:
                rbevers Russell Bevers
              • Votes:
                2 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated: