Ray
Ray

Reputation: 41488

Increase the Jenkins login timeout

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.

Upvotes: 99

Views: 73341

Answers (12)

Wilfred Hughes
Wilfred Hughes

Reputation: 31171

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.

Upvotes: 85

jhuffaker
jhuffaker

Reputation: 621

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.

See the full description on CloudBees' site:
Customizing Jenkins login session timeout

Upvotes: 40

vasja
vasja

Reputation: 21

If jenkins installed as debian package (ie with apt), then with Ubuntu 20.04 what worked for me overriding service configuration:

systemctl edit jenkins
# add user session timeout config
Environment="JENKINS_OPTS=--sessionTimeout=720 --sessionEviction=43200"

To see all jenkins OPTS, run command:

java -jar /usr/share/java/jenkins.war --help

Source: https://www.jenkins.io/doc/book/system-administration/systemd-services/

Upvotes: 1

seikamoomoo
seikamoomoo

Reputation: 1

For anyone on CentOS, web.xml will likely be in /var/lib/jenkins/%C/jenkins/war/WEB-INF/. In web.xml, you can add the session timeout and eviction settings to the session config like so:

  <session-config>
    <session-timeout>480</session-timeout>
    <session-eviction>12600</session-eviction>
  </session-config>

Leaving this here for anyone who struggled to find that file like I did.

Upvotes: 0

Adrian Jimenez
Adrian Jimenez

Reputation: 1157

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

Upvotes: -1

Jeff Mergler
Jeff Mergler

Reputation: 1532

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.

Upvotes: 0

VLL
VLL

Reputation: 10165

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

Upvotes: 0

Sven Keller
Sven Keller

Reputation: 621

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

Upvotes: 11

RocketKittens
RocketKittens

Reputation: 459

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"

Upvotes: 16

Steve Jones
Steve Jones

Reputation: 1568

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

Upvotes: 7

cesar
cesar

Reputation: 11072

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>

Upvotes: 12

Raghav Vaidhyanathan
Raghav Vaidhyanathan

Reputation: 905

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

Upvotes: 4

Related Questions