schedule a groovy script

Hello, 

I want to schedule a groovy script every first day of months. 

After researching on the net, I have found some links:

 

DO YOU KNOW ANY OTHER SIMPLE SOLUTIONS? 
Like executing the groovy script from a command line on linux?

 

 

 

1 answer

Best thing would be to upgrade your jira.

Second would be to use the cron tab on your OS to execute a script via curl: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_executing_built_in_scripts_remotely

Otherwise, you can have it run every 1440 minutes, then exit if it's not the first of the month.

@Jamie Echlin [Adaptavist] 

 

"Otherwise, you can have it run every 1440 minutes, then exit if it's not the first of the month."

How to do that? 
On System->Services? 

@Jamie Echlin [Adaptavist]

On System->Services, we can add a schedule service running every XXX minutes. But you said "exit if it's not the first of month"; where can I put this condition? 

 

@Jamie Echlin (Adaptavist)

But I have to change my groovy script???

@Jamie Echlin [Adaptavist]

 

import org.apache.log4j.Category
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.*;
import java.sql.Timestamp

 

Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
int currentDay = localCalendar.get(Calendar.DATE);
println currentDay


if ( currentDay == 18 ){
println "WE ARE IN CURRENT DAY _script Somme Precedent"

def jqlSearch = "project = 'AISC - Suivi des demandes' and status was in (Validation) and ('Date de livraison' >= startOfMonth(-1) and 'Date de livraison' <=endOfMonth(-1))"
def userManager = ComponentAccessor.getUserManager()
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponentOfType(SearchService)

def user = userManager.getUserByName("yk3520").directoryUser
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)


def value = 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObjectByName("Temps d'intervention")


if (parseResult.isValid()) {
try {
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
issues.each {
if (it.getCustomFieldValue(myCustomField))
value += it.getCustomFieldValue(myCustomField).toInteger()

}
} catch (SearchException e) {
e.printStackTrace()
}
} else {
log.warn("Invalid query")
return null
}


// Save the value at custom field with name A number custom field of issue with key TEST-1
def targetIssue = issueManager.getIssueByCurrentKey("SL-8")
def customField = customFieldManager.getCustomFieldObjects(targetIssue).find {it.name == "Total intervention M-1"}
if (customField) {
def changeHolder = new DefaultIssueChangeHolder()
customField.updateValue(null, targetIssue,
new ModifiedValue(targetIssue.getCustomFieldValue(customField), value.toString()),changeHolder)
log.debug "Custom field $customField.name} updated with value ${value}"
return
}

log.warn "Custom field ${customField?.name} was not updated"

 


}
else
{
println "WE ARE NOT IN CURRENT DAY"
}

Stop cross-posting. It doesn't help. It makes it much harder for people to help you.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,442 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you