Adding Javascript to config.groovy

93 views
Skip to first unread message

Parichay Barpanda

unread,
May 21, 2020, 3:54:26 PM5/21/20
to Jenkins Developers
Hi,

I am looking for a way to add Javascript to config.groovy files in my resources. It is possible to do so in jelly with <script> tags. Is it possible to write JS in groovy?

Thanks and Regards,
Parichay

Gavin Mogan

unread,
May 21, 2020, 3:56:09 PM5/21/20
to Jenkins Developers
Whats a config.groovy compared to config.jelly? Are you writing a plugin using groovy?

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/11d2e5ed-89ce-4727-96f8-e0e62ef35576%40googlegroups.com.

Parichay Barpanda

unread,
May 21, 2020, 4:07:29 PM5/21/20
to Jenkins Developers


On Friday, May 22, 2020 at 1:26:09 AM UTC+5:30, Gavin Mogan wrote:
Whats a config.groovy compared to config.jelly? Are you writing a plugin using groovy?

On Thu, May 21, 2020 at 12:54 PM Parichay Barpanda <parichay...@gmail.com> wrote:
Hi,

I am looking for a way to add Javascript to config.groovy files in my resources. It is possible to do so in jelly with <script> tags. Is it possible to write JS in groovy?

Thanks and Regards,
Parichay

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

Gavin Mogan

unread,
May 21, 2020, 4:24:46 PM5/21/20
to Jenkins Developers
Oh wow, I didn't know that was a thing.

Apparently you can use raw()


My grepping didn't turn up any other options. I'd be concerned that raw() isn't doing any xss escaping though, so someone else will have to speak to that.

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e4d2b0b7-dc5d-4ee3-b449-7bb90b5f73dd%40googlegroups.com.

Parichay Barpanda

unread,
May 21, 2020, 4:35:57 PM5/21/20
to Jenkins Developers
Thanks. I first saw groovy style config in GitHub Plugin and feel it more convenient over jelly because lack of IDE support make tags unreadable.

Daniel Beck

unread,
May 28, 2020, 6:39:55 AM5/28/20
to JenkinsCI Developers

On Thu, May 21, 2020 at 10:35 PM Parichay Barpanda <parichay...@gmail.com> wrote:
because lack of IDE support make tags unreadable.


There are IDE plugins adding support for this.

Jesse Glick

unread,
May 28, 2020, 7:27:54 AM5/28/20
to Jenkins Dev
On Thu, May 21, 2020 at 3:54 PM Parichay Barpanda
<parichay...@gmail.com> wrote:
> I am looking for a way to add Javascript to config.groovy files in my resources. It is possible to do so in jelly with <script> tags. Is it possible to write JS in groovy?

You are better off using `st.adjunct` so you can keep `*.js` and/or
`*.css` files separate.

Esther Alvarez

unread,
May 29, 2020, 5:47:06 AM5/29/20
to Jenkins Developers
I can not agree more with this. Keeping javascript code in a .js file is the best approach. Writing javascript using jelly (the script tag option) can seem easier, but it leads to a lot of problems and XSS attacks, and you will have to escape some special XML characters as well (&,<,>) which is a pain.

To pass around data from jelly to javascript, you can write "data-" attributes in HTML tags with jelly and then load them with javascript. Here some examples about how to do it: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

Daniel Beck

unread,
May 30, 2020, 12:00:19 PM5/30/20
to jenkin...@googlegroups.com


> On 29. May 2020, at 11:47, Esther Alvarez <ealv...@cloudbees.com> wrote:
>
> To pass around data from jelly to javascript, you can write "data-" attributes in HTML tags with jelly and then load them with javascript. Here some examples about how to do it: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

Also https://jenkins.io/doc/developer/security/xss-prevention/

Reply all
Reply to author
Forward
0 new messages