2

I wrote a PHP script to run Jenkins build . It was working fine but now I applied some security and created users that can run jenkins builds.

<?php
   echo "Run Jenkins\n";
echo shell_exec("curl -X POST http://198.0.0.21:8080/job/test/build");
echo "\n\n";
?>

Now I have a user e.g. test and with password test . How Can I rewrite my PHP script to use this user as authentication to run builds

I get the following output when I run the above script:

Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

I found the solution:

$u="test";
$p="test";
echo shell_exec("curl -X POST http://$u:$p@198.0.0.21:8080/job/test/build");
Developer
  • 817
  • 2
  • 16
  • 28

1 Answers1

0

If the version of jenkins you are running is greater than 1.426, you can generate a token to use in place of password so that you aren't revealing your password in plaintext.

See https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients

hofan41
  • 1,438
  • 1
  • 11
  • 25