Increase the Jenkins login timeout

JenkinsHudson

Jenkins Problem Overview


Does anyone know how to increase the the timeout window before Jenkins logs out a user? I'm looking to raise it to 1 day or so.

I work in and out jenkins all day and we keep getting logged out between running of jobs. Added to this frustration, the 'stay logged in' checkbox doesn't seem to work either.

Jenkins Solutions


Solution 1 - Jenkins

Jenkins uses Jetty, and Jetty's default timeout is 30 minutes. This is independent of authentication settings -- I use Active Directory but it's still this setting that affects timeouts.

You can override the timeout by passing an argument --sessionTimeout=<minutes> to the Jenkins init script, or -DsessionTimeout=<minutes> to the .war file. For example:

# Set the session timeout to 1 week
$ java -jar jenkins.war --sessionTimeout=10080

Alternatively, you can edit Jenkins' <jenkinsHome>/.jenkins/war/WEB-INF/web.xml and add explicitly set it:

<session-config>
  <!-- one hour -->
  <session-timeout>60</session-timeout>
</session-config>

According to Oracle's docs you can set this to 0 to disable timeouts altogether.

To find out the current value for timeouts, you can use the Groovy console provided in Jenkins:

import org.kohsuke.stapler.Stapler;
Stapler.getCurrentRequest().getSession().getMaxInactiveInterval() / 60

On my instance, this shows Result: 30.

Solution 2 - Jenkins

As of Jenkins version 2.107.2 you'll want to include sessionEviction

For example to keep people logged in for 24 hours and 12 hours of inactivity:

--sessionTimeout=1440 --sessionEviction=43200

If you don't specify sessionEviction people who close the tab will get logged out after 30 minutes.

Solution 3 - Jenkins

As of 1.528 you can use the --sessionTimeout <minutes> parameter when starting up jenkins via an init script. If starting the war, pass in -DsessionTimeout=<minutes>

Update for 1.6

If passing in as an arg use --sessionTimeout=<minutes>

Solution 4 - Jenkins

For Ubuntu:

nano /etc/default/jenkins

Append to JENKINS_ARGS at the end of the file:

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --sessionTimeout=1440 --sessionEviction=43200"

Solution 5 - Jenkins

it also seems possible to set it using groovy console:

import org.kohsuke.stapler.Stapler;
Stapler.getCurrentRequest().getSession().setMaxInactiveInterval(TIME_IN_SECONDS)

But I guess it will only be available for current session

Solution 6 - Jenkins

On my Linux distro, this setting can be added to /etc/sysconfig/jenkins

# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS="--sessionTimeout=480"

Subsequently, restart with

sudo /etc/init.d/jenkins restart

Solution 7 - Jenkins

This version of Jenkins 1.567 also has the enable auto refresh option so it somehow keeps refreshing the session and I never get logged out. It works for me...

Solution 8 - Jenkins

If Jenkins is running as a Windows service (jenkins.exe), parameters can be edited in jenkins.xml in the installation directory.

Solution 9 - Jenkins

Working with Jenkins 2.2x on Windows Server as a windows service the setting

--sessionTimeout=1440 --sessionEviction=43200

can be added here

<arguments>... -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" ... --sessionTimeout=1440 --sessionEviction=43200</arguments>

located in file jenkins.xml in the Jenkins folder, which for me was:

C:\Program Files\Jenkins on Windows Server 2012.

C:\Program Files (x86)\Jenkins on Windows Server 2008 R2

Restart the service for the change to take effect.

Solution 10 - Jenkins

After dealing with this for a couple hours and making sense of everything said here this is what I did to solve the issue:

  1. Log as sudo user
  2. cd /var/cache/jenkins/war/WEB-INF/
  3. vi web.xml
  4. Type "i" to go to insert mode
  5. Go down until you find <Session-Config> and type as screenshot
  6. Hit Esc
  7. Type :wd to save your changes
  8. sudo systemctl restart jenkins

Screenshot:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRayView Question on Stackoverflow
Solution 1 - JenkinsWilfred HughesView Answer on Stackoverflow
Solution 2 - JenkinsjhuffakerView Answer on Stackoverflow
Solution 3 - JenkinscesarView Answer on Stackoverflow
Solution 4 - JenkinsRocketKittensView Answer on Stackoverflow
Solution 5 - JenkinsSven KellerView Answer on Stackoverflow
Solution 6 - JenkinsSteve JonesView Answer on Stackoverflow
Solution 7 - JenkinsRaghav VaidhyanathanView Answer on Stackoverflow
Solution 8 - JenkinsVLLView Answer on Stackoverflow
Solution 9 - JenkinsJeff MerglerView Answer on Stackoverflow
Solution 10 - JenkinsAdrian JimenezView Answer on Stackoverflow