Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Re-index Jira through PowerShell script

Travis Duffy November 15, 2017

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 votes
Answer accepted
Brant Schroeder
Community Champion
November 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)"
}
Travis Duffy November 15, 2017

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
TAGS
AUG Leaders

Atlassian Community Events