Jelly script changelogset date issue with Mercurial plugin

44 views
Skip to first unread message

Arun Chandrasekaran

unread,
Jun 26, 2017, 4:42:03 PM6/26/17
to Jenkins Developers
Hi,

I'm reposting this from Jenkins-Users group.

I have a jelly script that displays the ChangeLogSet.date. Here is the snippet https://bpaste.net/show/b1dfd27acf66

https://09023362727002364442.googlegroups.com/attach/12eced734a856/Auto%20Generated%20Inline%20Image%201?part=0.1&view=1&vt=ANaJVrH_5fV5jlHx3oXfcGNrojEb0ZMZR2Jb6ewXkJAfoupk-MQRd9Ckd7bPES5NOPMwkpc3Qu7eQZGn8uPaVM41qg2NNsd7AkRjrnn98aYQvuszniwC5F4

However this displays cs.date as UNIX timestamp, as given by the mercurial plugin and not as string format.

Is there a way to convert UNIX timestamp to string in the jelly script? or does this require a fix in the Jenkins mercurial plugin?

Any help is appreciated.

Cheers,
Arun

Jesse Glick

unread,
Jun 26, 2017, 5:32:46 PM6/26/17
to Jenkins Dev
On Mon, Jun 26, 2017 at 4:40 PM, Arun Chandrasekaran
<vision...@gmail.com> wrote:
> Is there a way to convert UNIX timestamp to string in the jelly script?

http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html#getTimestamp--

Daniel Beck

unread,
Jun 26, 2017, 6:04:39 PM6/26/17
to jenkin...@googlegroups.com

> On 26. Jun 2017, at 23:32, Jesse Glick <jgl...@cloudbees.com> wrote:
>
> http://javadoc.jenkins-ci.org/hudson/scm/ChangeLogSet.Entry.html#getTimestamp--

That's a long. I think this asks for how to get a human readable date.

Jesse Glick

unread,
Jun 26, 2017, 6:18:22 PM6/26/17
to Jenkins Dev
On Mon, Jun 26, 2017 at 6:04 PM, Daniel Beck <m...@beckweb.net> wrote:
> That's a long. I think this asks for how to get a human readable date.

Yes, I left that as an exercise for the reader. My point was that this
is the generic API implemented by all SCMs, so there is no special
consideration for the `mercurial` plugin.

Oleg Nenashev

unread,
Jun 30, 2017, 11:40:47 PM6/30/17
to Jenkins Developers
So, somebody needs to create a bug to the core

вторник, 27 июня 2017 г., 0:18:22 UTC+2 пользователь Jesse Glick написал:

Daniel Beck

unread,
Jul 1, 2017, 7:04:39 AM7/1/17
to jenkin...@googlegroups.com

> On 1. Jul 2017, at 05:40, Oleg Nenashev <o.v.ne...@gmail.com> wrote:
>
> So, somebody needs to create a bug to the core

What's the bug? That the API doesn't support every imaginable representation of a date?

new Date(x.timestamp) (or rather its equivalent in Jelly) and you're done.

Arun Chandrasekaran

unread,
Jul 13, 2017, 4:50:22 AM7/13/17
to Jenkins Developers

Thanks Jesse. I'm not able to figure out how to convert or embed that into a Jelly.

Here is what I've attempted. Am I missing something?

            <SPAN class="name">
               ${aUser != null ? aUser.displayName : cs.author.displayName} on
                ${
                     java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MMM-dd HH:mm:ss z");
                     java.util.Date dt = new java.util.Date(${cs.date});
                     sdf.format(dt);
                }
           
</SPAN>


Jesse Glick

unread,
Jul 13, 2017, 9:40:39 AM7/13/17
to Jenkins Dev
On Wed, Jul 12, 2017 at 1:35 PM, Arun Chandrasekaran
<vision...@gmail.com> wrote:
> I'm not able to figure out how to convert or embed that into a Jelly.

Do not attempt to put any nontrivial logic into a Jelly view—anything
beyond simple property accesses (`obj.prop`), `j:if` switches, etc.
should be considered suspect. Define Java methods in your plugin that
does all the real work, and have the view just fetch the result.
Reply all
Reply to author
Forward
0 new messages