How to set a JVM option in Jenkins globally for every job?

五迷三道 提交于 2019-12-23 06:56:12

问题


I've recently installed a new JDK (1.7u9), and I got some very strange VerifyErrors. In a thread I found that it could help me if I use a -XX:-UseSplitVerifier magic switch for the compilation.

What I would like to do is to set this Java option globally in Jenkins, but haven't found any configurations for it. Can someone help me out how can I do this?

The closest thing I was able to come up with is to set the argument through Maven, but I have to do it for each project configuration - and I'd like to avoid that.

Thanks in advance.


回答1:


Under the main menu item Manage Jenkins->Configure System you can set it in the box for Global MAVEN_OPTS.

It is a bit unclear whether you want the option turned on for the Jenkins container itself or only the jobs running in it, but if the latter and you're only running maven jobs, that's what I would do.

Cheers,




回答2:


If you deploy the Jenkins to the Tomcat or Glassfish, I would like to suggest you to set further configuration as the following:-

The Tomcat

Set the environment variable named CATALINA_OPTS, e.g.

SET CATALINA_OPTS="-XX:-UseSplitVerifier"
EXPORT CATALINA_OPTS

The Glassfish

Edit the [your_domain]/config/domain.xml

<java-config ....>
    ....
    <jvm-options>-XX:-UseSplitVerifier</jvm-options>
</java-config>

Anyhow if you deploy it to another application server, please refer to your application server administrator guide to configure further JVM options.

UPDATED:

If you only would like to apply this JVM option to the Maven project, please set the environment variable named MAVEN_OPTS, e.g.

SET MAVEN_OPTS="-XX:-UseSplitVerifier"
export MAVEN_OPTS

I hope this may help.

Regards,

Charlee Ch.




回答3:


On Windows there's a jenkins.xml in Jenkins home directory. Simply add the required JVM options under arguments tag:

<arguments>
    -Xrs -Xmx256m -XX:-UseSplitVerifier 
    -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle 
    -jar "%BASE%\jenkins.war" --httpPort=8080
</arguments>

For most of the Linux distributions, modify JENKINS_ARGS inside file: /etc/default/jenkins (or jenkins-oc)

For CentOS, modify JENKINS_JAVA_OPTIONS inside file: /etc/sysconfig/jenkins (or jenkins-oc)




回答4:


Apparently, the only way to set system-wide JVM properties in Jenkins is with a Groovy Script .

Create a init.groovy.d in Jenkins home and place a groovy file in it (load-properties.groovy). In the Groovy script, set system properties programmatically (see link above for details):

       props.each { key, value ->
        System.setProperty(key, value)

The above solution saved my day as I needed to disable jsse.enableSNIExtension during SCM checkout and it should be available to the SVN plugin, not to Maven.

There's a config.xml file with jdks/jdk/properties XML tags, but it's undocumented.



来源:https://stackoverflow.com/questions/12930529/how-to-set-a-jvm-option-in-jenkins-globally-for-every-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!