It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[GROOVY] Run from console

Maciej Olszewski Jul 11, 2017

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

0 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017 • edited

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 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017

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 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017

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 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017

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 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017

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 votes
Adam Markham [Adaptavist] Community Leader Jul 11, 2017

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar invitation: Generate custom Jira Cloud PDF reports and exports

Jira may be a staple part of your workday, but your colleagues, customers, business partners or an auditor might need information presented in a different format, that is easy to access and read. And...

42 views 0 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you