Best way to send XML results from a curl - jenkins

we have a Jenkins pipeline that sends a sh 'curl' request to a an api/application to runs specific tests for us, and we fail/pass the build depending on the results.
What I want to do: is to parse the information we get back from the curl (XML document) and send these notifications via Slack.
What I've done so far is exactly that, parse the XML document, able to print the results locally, but when I try to send this result to slack I get a error: I am assuming this is because I saved my results as an Array, and when I am trying to send the information to slack its unable to reference the variable.
My question is: How should we send XML results to Slack and how can we properly parse the XML file and send it to slack?
My code snippet:
List <String> someString = new ArrayList<String>()
parsed = new XmlSlurper().parse("${workspace}/tmp/TESTS-results.xml")
parsed.testsuite.testcase.each { device ->
someString.add(device.#name)
someString.add(device.#time)
someString.add(device)
println deviceArr
println deviceArr.getClass()
}
parsed= XmlUtil.serialize(parsed)
return deviceArr
}
in field groovy.lang.GString.values
in object org.codehaus.groovy.runtime.GStringImpl#40198fcc
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2#4a4ae500
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#5dd0e25c
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#5dd0e25c
Caused: java.io.NotSerializableException: groovy.util.slurpersupport.Attributes

Related

Use generic-webhook-trigger and pass JSON body as is instead of individual variables

I am using generic-webhook-trigger in Jenkins to trigger job when events happen in Github.
It seems I have to extract each variable I need from the big JSON request body to convert them to env-var.
Is it possible to pass the whole JSON body to the Jenkins job and have it parse it?
You can achieve what you want by assigning the entire body to a specific variable, then read it as Json in your code and parse it by yourself.
For example, if your payload (received post content) is:
{
"ref": "refs/heads/master",
"head_commit": {
"committer": {
"name": "ido",
"email": "ido#test.com"
}
}
}
You can define a single parameter in your generic webhook configuration called payload, set the expression for that parameter to $, set the expressionType JSONPath, and when the job is triggered that parameter will include the entire content of the received post content.
You can then parse it by yourself:
def payloadMap = readJSON text: payload
println "ref value is: ${payloadMap.ref}"
println "committer name is: ${payloadMap.head_commit.committer.name}"
You can see more advanced examples for using the generic-webhook-trigger configurations plugin Here, and especially This one which is more relevant for your requirements.

Power Automate error when trying to add an attachment array from plumsail

I have a Plumsail form where a user can attach several pdf or word documents. In power automate I create an array of these documents and then attach the array to the "Start and wait for approval" action. When I run it, I get the error below:
The request failed. Error code: 'InvalidRequestContent'. Error
Message: 'The request content was invalid and could not be
deserialized: 'Could not find member 'ContentBytes' on object of type
'ApprovalsConnectorAttachment'.
I'm assuming you followed the How to send an email from Plumsail form with Power Automate Plumsail guide as it tells you to assign the HTTP GET file response to a property named ContentBytes.
While this will work with the Send an Email (V2) action (from the guide) the Start and wait for an approval action expects a property named content content.
To fix the problem append the following object to the array (note the contentproperty):
{
"name": #{items('Apply_to_each_2')?['file']},
"content": #{body('HTTP')}
}
or as an image:

PowerApps Custom Connector: How to POST binary data in request body?

Using Postman to test an API, I'm able to select Body/binary then choose an image file stored locally. Postman inserts binary data somehow into the request and I get a favorable response:
When trying to build this as a Custom Connector in PowerApps, I can't find any info on what the schema for the Body of the request should be.
When I try to add a generic {"body": ""} body to the connector with a string type of binary, I receive this error:
Specified swagger has the following errors: 'Definition is not valid. Error: 'Error : paths/~1prebuilt~1analyze/post/parameters/2/schema/properties/body : A schema with type/format 'string/binary' can only be at the top level of a body or formData parameter. '
I was running into the same problem.
Body:
""
When you have clicked Import, go to the request -> body -> body and click the three dots -> Edit.
Under Body, it will say "key-body-output". Click the three dots and click Edit.
Change Type to String (if not already) and change Format to Binary. Change Is required to Yes.
Update the connector and you can now use the custom connector with PowerApps by using ImageX.Image for the body property for example.

How to get Response from another channel in mirth

We have two channels called channelA and channelB.
In channelA we have two destinations
a. first destination will invoke the channelB with XML data as input and get the response from the channelB in XML format.
b. retrieve the response of first destination in xml format and process it.
var dest1 = responseMap.get("destination1");
var resMessage = dest1.getMessage();
I am getting channelB response as "Message routed successfully".
How I will get actual XML from channelB instead of "Message routed successfully" message.
We are doing above steps to define generic channels such that we can reuse it in different scenarios in the mirth application.
We using mirth 2.2.1.5861 version.
We are doing something very similar to what you described. In our case, destination1 is a SOAP sender (SOAP uses XML for its send and receive envelopes). Here's the syntax we are successfully using in destination2 JavaScript Writer:
var dest1 = responseMap.get("destination1");
var resMessage = dest1.getStatus().toString();
if (resMessage == "SUCCESS")
{
var stringResponse = dest1.getMessage();
channelMap.put('stringResponse',stringResponse);
var xmlResponse = new XML(stringResponse);
// use e4x notation to parse xmlResponse
}
If your destination1 is not a SOAP sender, then the XML response from channelB might be getting packaged up in some way that you need to extract from "stringResponse." You can see the contents of the channelMap variable "stringResponse" after running the message through the channel. Go to the dashboard, double-click the channel, find a message that has been sent, and then look at the mappings tab. What does the content of "stringResponse" actually look like? Is it just "Message routed successfully?" Or is that text followed by the XML that you're after?
Create ChannelB having source data type as an XML, and put source as a channel reader.
You have to make a single destination on ChannelA as a Channel Writer, and put ChannelB in the details.
This way whatever message you get in the form of an XML in ChannelAwill be routed to ChannelB.

IMAP - javax.mail. - Fetching Only Body Without Attachment

I am trying to develop an IMAP email client using the javax.mail API. I have been able to contact the servers, fetch emails, attachments and other operations without any problem.
However, we would not want to fetch the attachment until the user wants to view it explit in order to improve the performance. This would mean that we would need information which would indicate if the email has an attachment, if yes, then the filename(s) and the size(s)but would not send me the actual content of the email. However, I was not able to find a method in the API description which would return just the multi-part content.
Is there a way I could fetch just the body and the details of the attachment but not the actual attachment?
Thanks,
Aravind
The method getContent() of javax.Part returns
the content as a Java object. The type
of the returned object is of course
dependent on the content itself. For
example, the object returned for
"text/plain" content is usually a
String object. The object returned for
a "multipart" content is always a
Multipart subclass.
See http://download.oracle.com/javaee/6/api/javax/mail/Part.html#getContent%28%29
If a Message (which is a Part) contains attachments, the getContent method will return a Multipart object. In addition you can know the MIME type of the part with getContentType.
The information that is missing from the documentation is that this MultiPart object returned by getContent is just an empty representation of the Message's structure. The content of each Part of the Multipart will only be fetched from the server when you specifically ask for it. For example, to parse a multipart Message you would do:
if( p.isMimeType("multipart/*") ) {
Multipart mp = (Multipart)p.getContent();
// the content was not fetched from the server
// parse each Part
for (int i = 0; i < mp.getCount(); i++) {
Part inner_part = mp.getBodyPart(i)
if( inner_part.isMimeType("text/plain") ) {
String text = inner_part.getText();
// the content of this Part was fetched from the server
}
}
}
Something else to consider is that for optimal performance you should get the body structure information from the server in batch for the collection of messages you want to parse (see http://download.oracle.com/javaee/6/api/javax/mail/FetchProfile.Item.html#CONTENT_INFO). If not, each
Multipart mp = (Multipart)p.getContent();
will result in a request to the server to fetch the body structure. If the FetchProfile approach is used, the body structure for the collection of messages will be fetched with only one request. You can see the requests to the server in the log if you activate debug mode on the session:
session.setDebug(true);
This said, to get size and filenames of attachments just use Part.getSize() and Part.getFileName(), respectively.

Resources