Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Exiting jelly script by dayofweek [Jira]

Tamir Lavi June 29, 2013

Hi.

I am trying to exit Jelly script if it runs on the weekend.

I found some examples on retrieving the day of week.
I know it sound pretty simple... , but I wasn't able to get it to work.

How do you write a condition on Jelly Script?
How do you exit jelly script?

I would appreciate if anyone can give me a working example (I'm sure it be useful for many others...)

Thanks!

Tamir.

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Neil Arrowsmith
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2014

Hi

I had to do something like this, and have picked up some tips from other posts here. Mine is a little bit more complicated as I needed to act on tomorrow's date rather than today's. But hopefully the below helps. The important parts for your questions are the <core:if... > tags.

In summary this is set to run every day, creating an issue with tomorrow's date in the summary, unless tomorrow is a weekend day.

&lt;JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib" xmlns:core="jelly:core"&gt;
&lt;core:invokeStatic className="java.util.Calendar" method="getInstance" var="TomorrowCalendar"/&gt;
&lt;core:invoke on="${TomorrowCalendar}" method="add"&gt;
    &lt;core:arg type="int" value="5"/&gt;
    &lt;core:arg type="int" value="1"/&gt;
&lt;/core:invoke&gt;
&lt;core:invoke on="${TomorrowCalendar}" method="get" var="dayOfweek"&gt;
    &lt;core:arg type="int" value="7"/&gt;
&lt;/core:invoke&gt;
&lt;core:if test="${dayOfweek != 1}"&gt;
    &lt;core:if test="${dayOfweek != 7}"&gt;
        &lt;core:new className="java.text.SimpleDateFormat" var="format"&gt;
            &lt;core:arg type="java.lang.String" value="yyyy-MM-dd" /&gt;
        &lt;/core:new&gt;
        &lt;core:new className="java.text.SimpleDateFormat" var="dayformat"&gt;
            &lt;core:arg type="java.lang.String" value="EEEE" /&gt;
        &lt;/core:new&gt;

        &lt;core:invoke on="${TomorrowCalendar}" var="TomorrowDate" method="getTime"/&gt;
        &lt;core:invokeStatic className="java.util.TimeZone" method="getTimeZone" var="timezone"&gt;
	    &lt;core:arg type="java.lang.String" value="GMT" /&gt;
	&lt;/core:invokeStatic&gt;
	&lt;core:invoke on="${format}" var="formattedDate" method="setTimeZone"&gt;
	    &lt;core:arg type="java.util.TimeZone" value="${timezone}" /&gt;
	&lt;/core:invoke&gt;
        &lt;core:invoke on="${format}" var="formattedDate" method="format"&gt;
            &lt;core:arg type="java.util.Date" value="${TomorrowDate}" /&gt;
        &lt;/core:invoke&gt;
        &lt;core:invoke on="${dayformat}" var="formattedDOW" method="format"&gt;
            &lt;core:arg type="java.util.Date" value="${TomorrowDate}" /&gt;
        &lt;/core:invoke&gt;        
        
        &lt;jira:CreateIssue project-key="REL" summary="Daily Release ${formattedDOW} ${formattedDate}" assignee="-1" duplicateSummary="ignore" /&gt;
    &lt;/core:if&gt;
&lt;/core:if&gt; 
&lt;/JiraJelly&gt;

Tamir Lavi March 16, 2014

Hi Neil Arrowsmith

It's been some time since I posted that question...
I realy appreciate your effort to share the solution with us.

Although I did not yet test it, I going to mark your answer as accepted, as it seems to solve the problem I had.

Thanks!

0 votes
Neil Arrowsmith
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2014
Hi Ravi
This bit of the script above checks if the day is a Sunday (dayOfweek == 1) or Saturday (dayOfweek == 7)...
&lt;core:if test="${dayOfweek != 1}"&gt;
    &lt;core:if test="${dayOfweek != 7}"&gt;
0 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2014

Just amazing code, I am wondering how the code finds out whether the date is weekend or not?

0 votes
Tamir Lavi July 6, 2013

Hi, David.

I guess that if I'll spend enough time on that issue, I will figure it out.
Problem is that I don't have a full day to spend on it, and I am not a jelly script expert.

So, if some have a working example - I would appriciate it.

The flow I need is:

1. If now().dayofweek is in [day of weekend] -> EXIT.

2 Else continue with the Jelly script.

0 votes
David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2013

You will already be familiar with the Jelly tags for JIRA. For general flow control and logic, you may want to read about the tags in the jelly:core library.

Perhaps you have already read my answer to the question about retrieving the value of a custom date field, in which case, you have an example of using Jelly to make arbitrary calls to Java methods using the core:invoke and core:invokeStatic tags. There's anther example of using those tags in my answer to Jira Jelly how do I add label to an issue?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events