Jenkins - Posting results to a external monitoring job is adding garbage to the build job log

999 views Asked by At

I have a external monitor job that I'm pushing the result of another job to it with curl and base on this link :

Monitoring external jobs

After I create the job I just need to run a curl command with the body encoded in HEX to the specified url and then a build will be created and the output will be added to it but what I get instead is part of my output in clear text and the rest in weird characters like so :

Started
Asking akamai to purge this urls:
http://xxx/sites/all/modules/custom/uk.png     http://aaaaaasites/all/modules/custom/flags/jp.png
<html><head><title>401 Unauthorized</title>    </h�VC��&�G����CV�WF��&��VC�������R&R��BWF��&��VBF�66W72F�B&W6�W&6S�����&�G�����F����F�RW&�F �6�V6�7FGW2�bF�R&WVW7B�2��F�RF��RF�v�B�2��6�Ɩ�r&6�w&�V�B��"F�6�V6�7FGW2�bF�RF�6�W@�v�F��rf�"���F�W&vRF��6O request please keep in mind this is an estimated time
Waiting for another 60 seconds
Asking akamai to purge this urls:
...
..
..

This is how I'm doing it :

export output=`cat msg.out|xxd -c 256 -ps`

curl -k -X POST -d "<run><log encoding=\"hexBinary\">$output</log><result>0</result>  <duration>2000</duration></run>" https://$jenkinsuser:[email protected]/jenkins/job/akamai_purge_results/postBuildResult -H'.crumb:c775f3aa15464563456346e'

If I cat that file is all fine and even if I edit it with vi I can't see any problem with it.

Do you guys have any idea how to fix this ?

Could it be a problem with the hex encoding ? ( I tried hex/enc/dec pages with the result of xxd and they look fine)

Thanks.

1

There are 1 answers

1
Taytay On

I had the same issue, and stumbled across this: http://blog.markfeeney.com/2010/01/hexbinary-encoding.html

From that page, you can get the encoding you need via this command: echo "Hello world" | hexdump -v -e '1/1 "%02x"' 48656c6c6f20776f726c640a

An excerpt from the explanation:

So what the hell is that? -v means don't suppress any duplicate data in the output, and -e is the format string. hexdump's very particular about the formatting of the -e argument; so careful with the quotes. The 1/1 means for every 1 byte encountered in the input, apply the following formatting pattern 1 time. Despite this sounding like the default behaviour in the man page, the 1/1 is not optional. /1 also works, but the 1/1 is very very slightly more readable, IMO. The "%02x" is just a standard-issue printf-style format code.

So in your case, you would do this (removing 'export' in favor of inline variable) OUTPUT=`cat msg.out | hexdump -v -e '1/1 "%02x"'` curl -k -X POST -d "<run><log encoding=\"hexBinary\">$OUTPUT</log><result>0</result> <duration>2000</duration></run>" https://$jenkinsuser:[email protected]/jenkins/job/akamai_purge_results/postBuildResult -H'.crumb:c775f3aa15464563456346e'