Hey all,
Has anyone gotten Callback to work when having JEC trigger PowerShell scripts via an Automation?
I've been trying, and cannot for the life of me get it to work.
I'm writing some very simple JSON back into the Named Pipe during the execution, but the smart value {{jecAction.output}} never returns anything other than "Execution Finished!"
Made it work in PowerShell, but the function is useless to us after all duo to how little data can be passed to the Named Pipe
I'm not that sure, that json would work. It took me some time to get it to work with strings. Assuming, you got the pipe info provided from the invocation ("\\.\pipe\jecCallbackPipe-xxxxxx") in a var called $jecNamedPipe, the code below should allow you to send back $resp
$resp = "No error"
$pipeName = [System.IO.Path]::GetFileName($jecNamedPipe)
$pipe = New-Object System.IO.Pipes.NamedPipeClientStream($pipeName)
$pipe.Connect() # waits for server
$writer = New-Object System.IO.StreamWriter($pipe)
$writer.AutoFlush = $true
$writer.WriteLine($resp)
$writer.Flush()
$writer.Dispose()
$pipe.Dispose()
With my initial setup, I tried to create a stream for $jecNamedPipe (the path) but NamedPipeClientStream only expects the name...
Hope this helped.
Best regards
Gideon from Eficode
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same question here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antoine,
I ended up getting a working script.
JEC Pipelines however has such a rediculously small character limit that it is unusable for our case.
Let me know if you want the working PowerShell code snippit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Benjamin, what do you mean by the jec pipeline (i don't know anything about powershell advanced scripting sorry)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JEC Uses a technology called Named Pipes to read data back into Jira Automation when you execute an on-premises script.
It's a small type of data storage that exists in-memory.
Issue is, Atlassian has coded JEC to close the storage when you write X amount of data (The largest data I could send back into Jira Automation was somthing like 1024 Characters, which doesn't give me a lot of room for data), which makes it basically unusable for us. This means when we use JEC to grab some data On-Premises with PowerShell and send it back through the Named Pipe, we could risk the comment containing the data to just cut off halfway through the paragraph.
I ended up writing a small PowerShell function that sends data back into Jira through the REST-API instead, to comment the data on the Work Item that triggered the Jira Automation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright thanks.
How do I "return" data to this "named pipe" ? Do you have some MWE in Powershell (and hopefully Python as well...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's a PowerShell Function you can use in your script to write some data to the pipe. You can adjust the sleep timers to something less than 5 seconds if your system can handle it.
The Parameter $PipeName is passed to your script by JEC as the 9'th argument. In your script you can access it with the variable $args[9]
So to use the function here in your script, you would as an example do:
Write-JecPipe -PipeName $args[9] -Content "FooBar"
Here's the function:
function Write-JecPipe {
param (
[Parameter(Mandatory = $true)]$PipeName,
[Parameter(Mandatory = $true)]$Content
)
$pipe = [System.IO.Pipes.NamedPipeClientStream]::new(".", $PipeName.Split("\")[4], [System.IO.Pipes.PipeDirection]::Out)
$pipe.Connect()
$writer = [System.IO.StreamWriter]::new($pipe)
$writer.AutoFlush = $false
$writer.Write($Content)
$writer.Flush()
Start-Sleep -Seconds 5
$writer.Close()
Start-Sleep -Seconds 5
$pipe.Close()
}
I'm unfortunately not proficcient in Python, byt Atlassian actually has an example of how to do this in Python
Check out their GitHub repo here: jec/_scripts/example.py at master · atlassian/jec · GitHub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome thanks a lot for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.