Enable or disable Job DSL "Enable script security for Job DSL scripts" option programatically

4,183 views
Skip to first unread message

Fábio Peruchi

unread,
Apr 20, 2017, 3:41:36 PM4/20/17
to job-dsl-plugin
Hi guys! What's up?

Is there a way to enable or disable Job DSL "Enable script security for Job DSL scripts" option in the https://<host>/configureSecurity/ Jenkins Global Security screen programatically via Jenkins Java API? Which class do I have to use to do it?

Thanks a lot!
Fabio

Victor Martinez

unread,
Apr 21, 2017, 4:46:33 AM4/21/17
to job-dsl-plugin
You can use the below snippet and then change the security option in Groovy

import javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration
import jenkins.model.GlobalConfiguration
import org.kohsuke.stapler.StaplerRequest

// current value  
println GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).useScriptSecurity

// change vaue
StaplerRequest stapler = null
net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject()
GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).configure(stapler, jsonObject)

// new value
println GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).useScriptSecurity


Cheers

Fábio Peruchi

unread,
Apr 21, 2017, 12:32:42 PM4/21/17
to job-dsl...@googlegroups.com
Thanks a lot Victor! It worked very well!  ☺


logo tecsinapse
Fábio Peruchi
DevOps / Infra-estrutura
ícone email fabio.peruchi​@​​tecsinapse​​.​com​​.​​br​
ícone phone (19) 98205-4446
ícone skype fabio_peruchi

Esta mensagem, incluindo seus anexos, tem caráter confidencial e seu conteúdo é restrito ao destinatário da mensagem. Caso você a tenha recebido por engano, queira, por favor, retorná-la ao destinatário e apagá-la de seus arquivos. Qualquer uso não autorizado, replicação ou disseminação desta mensagem ou parte dela é expressamente proibido. A TecSinapse não se responsabilizará pelo conteúdo ou pela veracidade desta informação.


--
You received this message because you are subscribed to a topic in the Google Groups "job-dsl-plugin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/job-dsl-plugin/BT8nEeLoBps/unsubscribe.
To unsubscribe from this group and all its topics, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/9913942f-82af-440e-aca8-a5c2ce04e261%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Glenn Van De Putte

unread,
May 11, 2017, 3:44:23 AM5/11/17
to job-dsl-plugin
Hi, 

Just for any other people struggling with this: the code Victor supplied didn't work for me, but simply executing:


import javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration
import jenkins.model.GlobalConfiguration

GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).useScriptSecurity=false


did do the trick for me. 

Thanks for the tip anyway!

To unsubscribe from this group and all its topics, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.

Fábio Peruchi

unread,
May 11, 2017, 10:08:43 AM5/11/17
to job-dsl...@googlegroups.com
Thank you Glenn. This second code option worked for me too. :-)


logo tecsinapse
Fábio Peruchi
DevOps / Infra-estrutura
ícone email fabio.peruchi​@​​tecsinapse​​.​com​​.​​br​
ícone phone (19) 98205-4446
ícone skype fabio_peruchi

Esta mensagem, incluindo seus anexos, tem caráter confidencial e seu conteúdo é restrito ao destinatário da mensagem. Caso você a tenha recebido por engano, queira, por favor, retorná-la ao destinatário e apagá-la de seus arquivos. Qualquer uso não autorizado, replicação ou disseminação desta mensagem ou parte dela é expressamente proibido. A TecSinapse não se responsabilizará pelo conteúdo ou pela veracidade desta informação.


To unsubscribe from this group and all its topics, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/b37b00fd-92b8-4587-9978-36b8d35c2875%40googlegroups.com.

Anssi Wilkko

unread,
Nov 12, 2017, 11:43:42 AM11/12/17
to job-dsl-plugin
Hi,

You need to call save to persist the configuration change over reboots:

import javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration
import jenkins.model.GlobalConfiguration

// Disable Job DSL script approval
GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).useScriptSecurity=false
GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class).save()

You can check the configuration.xml to verify change it persisted:
cat /var/lib/jenkins/javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration.xml
<?xml version='1.0' encoding='UTF-8'?>
<javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration plugin="job...@1.66">
  <category class="jenkins.model.GlobalConfigurationCategory$Security"/>
  <useScriptSecurity>false</useScriptSecurity>
</javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration>

-Anssi
Reply all
Reply to author
Forward
0 new messages