[GROOVY] Run from console

Hello,

I am using a lot of groovy scripts lately but i need to change date everytime, my question is can i run groovy scripts from console?
for example:
I have script deactivateUser where i need to change login of user, and i want to run it like that from console
/script/deactivateUser.groovy arg1

where arg1 is username :)
I hope this is possible! If yes can you show me how to use arg1 in script and how to run it from console?

Thanks in advance!
Maciej O.

6 answers

Hi Maciej,

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be:

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots def relativeFilePath = "userscripts/DeactivateUser.groovy"
// change to your username you want to deactivate def username = "user1" scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

 

0 vote

Hi Maciej,

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be: 

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots def relativeFilePath = "userscripts/DeactivateUser.groovy"
// change to your username you want to deactivate def username = "user1" scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

0 vote

Hi Maciej,

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be:

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots def relativeFilePath = "userscripts/DeactivateUser.groovy"
// change to your username you want to deactivate def username = "user1" scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

0 vote

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be:

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots def relativeFilePath = "userscripts/DeactivateUser.groovy"
// change to your username you want to deactivate def username = "user1" scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

0 vote

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be:

 

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots
def relativeFilePath = "userscripts/DeactivateUser.groovy"

// change to your username you want to deactivate
def username = "user1"

scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

0 vote

The easiest thing to do is to run it using the Script Console under Admin -> Script Console.

For example if you place your DeativateUser.groovy script under your script root (by default <jira-home>/scripts) so if you have it under "<jira-home>/scripts/userscripts/DeativateUser.groovy"

Your DeactivateUser.groovy script should have at the top:

package userscripts

Then the script you run in the Script Console would be:

 

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def scriptRunner = ScriptRunnerImpl.getScriptRunner()

// this is relative to the script roots
def relativeFilePath = "userscripts/DeactivateUser.groovy"

// change to your username you want to deactivate
def username = "user1"

scriptRunner.runFileAsScript(new File(relativeFilePath), [username: username])

You could even expand your script to take a list of usernames rather than just one.

Please see the docs here for information on script roots to double check you have your script in the correct place.

Hope this helps,

Thanks,
Adam

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

72 views 0 5
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