延长 Jenkins 登录超时

有人知道如何在 Jenkins 注销用户之前增加超时窗口吗?我希望能提高到一天左右。

我整天都在 Jenkins 家工作,我们总是在工作间隙退出。更令人沮丧的是,“保持登录”复选框似乎也不起作用。

62648 次浏览

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

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>

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.

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

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.

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

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"

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

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.

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