Re-index Jira through PowerShell script

I want to be able to trigger a Jira re-index from a Powershell script that will be scheduled to run.

 

The reason I am wanting to do this is because we have test instances of Jira that have their databases updated nightly.  Once the database is changed externally, Jira needs to be reindexed.  I want to be able to run this script nightly after the database update.

 

I have found the API for this, but I am not quite sure how to use this with a Powershell script ( https://docs.atlassian.com/jira/REST/server/#api/2/reindex )

 

Thank you!

1 answer

1 accepted

0 vote
Brant Schroeder Community Champion Nov 15, 2017

You will need to use the Invoke-RestMethod in Powershell to initiate the REST service.  I think something like this would work:

[string] $username = "username"
[string] $password = "password"

try {
$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{
"Authorization" = $basicAuth
"Content-Type"="application/json"
}
$requestUri = "https://jirahostname.com/rest/api/2/reindex"
$response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers
}
catch {
Write-Warning "Remote Server Response: $($_.Exception.Message)"
}

This did the trick!  Just had to switch the url from "...com/rest" to "...com/project/rest" and it worked like a charm.  Thank you so much!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

49 views 0 4
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