I am trying to execute the curl command from the groovy script on Jenkins. When I ran the script from the machine it is returning expected result. When I am trying to execute the same from Jenkins groovy it is giving null output.
The curl part that works when executed from the machine's command line:
authID=$(curl -sk $zabbixurl -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"user.login\", \"params\": { \"user\": \"$zabbixusername\", \"password\": \"$zabbix_password\" }, \"id\": 1}" )
The script I execute from Groovy:
def zabbix(){
sh """
AuthID=\$(curl -sk "\$zabbixurl" -H \\\"Content-Type: application/json\\\" -d \\\'{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"user.login\\\",\\\"id\\\":1,\\\"params\\\":{\\\"user\\\":\\\"\$zabbixusername\\\",\\\"password\\\":\\\"\$zabbix_password\\\"}}\\\' )
echo \$AuthID
"""
}