Closed npatgiri closed 5 years ago
Hi, I would like to support this feature.
I am not sure if it is already possible using:
#Invoke-WebRequest -Uri $JiraAttachment.Content
I have been playing around with it and so far been unsuccessful.
This can be done with current resources:
Invoke-JiraMethod -Uri (Get-JiraIssueAttachment -Issue TV-14).Content[0] -OutFile foo.txt
dir foo.txt
Directory Projects:\JiraPS Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2018-11-02 22:45 202 foo.txt
but... ConfluencePS has a dedicated command for this: https://github.com/AtlassianPS/ConfluencePS/blob/master/ConfluencePS/Public/Get-AttachmentFile.ps1
If you want to contribute, you can submit a PR implementing this for JiraPS :-)
I must be doing something incorrectly in my script, hoping you can help.
I am looping through all $JiraObjects I find in a specific filter, and then trying to find all ".PNG" attachments for a given issue and download them to my desktop to then use later on.
It seems nothing is found when I use the following code, I amended it to include what you suggested.
try {
$JiraIssueAttachment = Get-JiraIssueAttachment -Issue $JiraObject.Key -FileName "*.png" -Credential $Credentials
if ($JiraIssueAttachment.Count -ne 0) {
Invoke-JiraMethod -uri (Get-JiraIssueAttachment -Issue $JiraObject.Key -FileName "*.png" -Credential $Credentials).Content[0] `
-OutFile "$Env:USERPROFILE\Desktop\" + "$JiraObject.Id" + ".png"
}
}
catch {
Write-Verbose -Message "No Jira Attachments found for Jira Issue"
}
Yeah... that function needs some work... not the most user friendly. but try this:
Get-JiraIssue "TV-13", "TV-14" | Get-JiraIssueAttachment -ea 0 | % { Invoke-JiraMethod -Uri $_.content -OutFile $
_.filename }
Hi, could you advise on why it is not so user friendly? I would be glad to take your advice on board.
I have tried your suggestion and I did not have any success. I removed the "ea" switch so I could see the errors.
I need only .PNG attachments, so I added a filter for only these types of attachments. I also had to add the $Credentials to stop it from throwing the permission error.
I end up with this line:
Get-JiraIssue $JiraObject.Key -Credential $Credentials | Get-JiraIssueAttachment -Credential $Credentials -FileName "*.png" | % { Invoke-JiraMethod -Uri $_.content -OutFile $_.filename }
One thing is, I am not sure where these images would be saved on my machine by just supplying $_.filename?
My aim with this script is to aid our developers, so we don't have to manually create Release Notes. The script will just grab the content I need from Jira, and add them to a Word file or PDF. This will then be manually checked over before sending them out.
This is the error I got when running the script:
Invoke-JiraMethod : Oops, you've made a malformed request. - Atlassian accountwindow.baseUrl = 'https:\/\/aid-static-assets.prod.atl-paas.net\/atlassian-id\/14.3.29';window.AJS = {}; window.AJS.EventQueue = []; require(['internal/browser-metrics', 'herment'], function (metrics, herment) {var config =
{storage_key: 'aid', product: 'aid', subproduct: 'signup', save_interval: 20};herment(config).start();});Oops, you've made a malformed request.Often, clearing your browsers cache and restarting your browser will solve this problem.If that doesn't work, please contact support.Terms of UseSupportPrivacy
PolicyAtlassian
At C:\Users\MyUserName\Development\PowerShell\Create-ReleaseNotesFromJiraIssues.ps1:23 char:139
+ ... *.png" | % { Invoke-JiraMethod -Uri $_.content -OutFile $_.filename }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
+ FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod
Edit - I have resolved this, the Invoke-JiraMethod needed my credentials passing too. I would still be interesting in your thoughts on making this more user friendly.
hey @nickrobbo
could you advise on why it is not so user friendly?
sure. here a the ones I can identify without investigating too much:
JiraPS.Issue
provided to -Issue
"TV-13", "TV-14" | Get-JiraIssueAttachment
One thing is, I am not sure where these images would be saved on my machine by just supplying $_.filename?
In the current directory ($pwd.path
)
This is the error I got when running the script:
This looks strange. can you run the command with -verbose
and show the output?
I added -Credentials $Credential to the Invoke-JiraMethod command, and this resolved that error. It seems I have to pass these to each command.
Thanks for your input, I will go back and refactor the script. I guess I should share my full script for you to comment on, as I think it will make it clearer. I have just left out the part which prompts me for my credentials.
$JiraObjects = Get-JiraIssue -Filter $issuefilter -Credential $Credentials
if ($JiraObjects.Count -ne 0) {
$FilePath = "$Env:USERPROFILE\Desktop\Test.docx"
$WordDocument = New-WordDocument $FilePath
foreach ($JiraObject in $JiraObjects) { #Loop through all issues found in filter
$TextKey = $JiraObject.Key
$TextSummary = $JiraObject.Summary
$TextHeading1 = $TextKey + ' - ' + $TextSummary
Add-WordText -WordDocument $WordDocument -Text $TextHeading1 -FontSize 14 -HeadingType Heading2 # Add to Word Doc
Add-WordText -WordDocument $WordDocument -Text $JiraObject.Description -FontSize 12 # Add to Word Doc
Get-JiraIssue $JiraObject.Key -Credential $Credentials | Get-JiraIssueAttachment -Credential $Credentials -FileName "*.png" | % { Invoke-JiraMethod -Credential $Credentials -Uri $_.content -OutFile $Env:USERPROFILE\Desktop\$_ }
Add-WordPageBreak -WordDocument $WordDocument
}
Save-WordDocument $WordDocument -Supress $true
Invoke-Item $FilePath
} else {
Write-Host "No Issues found using specified filter!" -ForegroundColor Red
}
This is still a rough work in progress, so there are parts hard-coded which will not be in the end.
Great to hear you could make it work.
I only have two comments about your script. specifically this line:
% { Invoke-JiraMethod -Credential $Credentials -Uri $_.content -OutFile $Env:USERPROFILE\Desktop\$_ }
$_
, which you are passing to the -OutFile
parameter, is an object. I believe you want to use a property of $_
.Hi, yes I am in the process of adding the parts which will use the attachments, and then delete them once they have been added to the document. Sorry, I should have mentioned that.
In relation to point 1, when I used $_.filename
it would save the files as"ImageFileName.Filename".
So I changed it to just $_
and it seemed to resolve my issue.
great. if you need further help, please open a new issue or join us on slack
Thanks, you can now close this issue if you want.
Context
Description
Additional Information