0

I have a requirement where I need to send the status of the jenkins slave to influxdb. To do so I need to run a curl command from Jenkins Groovy script.

My script looks like this :

int value=0;
for (Node node in Jenkins.instance.nodes) {
   if (!node.toComputer().online){
   value=1;
   }
   else{
   value=0;
   }

curl -i -XPOST http://localhost:8086/write?db=jenkins_db&u=user&p=pass --data-binary 'mymeas,tag=$node.nodeName status=$value'

But after running the script values do not appear in influxdb. Any Idea what might be wrong here?

PS I also tried

def response = [ 'bash', '-c', "curl", "-i", "-XPOST", "http:/localhost:8086/write?db=jenkins_db&u=user&p=pass", "--data-binary", "\'mymeas tag=$node.nodeName status=$value"\' ].execute().text
StephenKing
  • 36,187
  • 11
  • 83
  • 112
Jitu
  • 5
  • 1
  • 7
  • you have to check the error output (stderr). by using `...execute().text` you partially get stdout. https://stackoverflow.com/questions/159148/groovy-executing-shell-commands – daggett Aug 29 '18 at 14:22
  • I run the script from a console provided at https://jenkinsurl/script There is no output printed. – Jitu Aug 31 '18 at 05:31
  • do you mean `println "hello world"` not printing output? which plugin are you using? – daggett Aug 31 '18 at 05:49

1 Answers1

0

You just need to echo your curl command

echo curl -i -XPOST http://localhost:8086/write?db=jenkins_db&u=user&p=pass --data-binary 'mymeas,tag=$node.nodeName status=$value'

proudfoot
  • 1
  • 2