简体   繁体   English

通过PHP远程运行jenkins脚本

[英]run jenkins script remotely via PHP

I wrote a PHP script to run Jenkins build . 我写了一个PHP脚本来运行Jenkins build。 It was working fine but now I applied some security and created users that can run jenkins builds. 一切正常,但现在我应用了一些安全性并创建了可以运行jenkins构建的用户。

<?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 eg test and with password test . 现在我有一个用户,例如test和password test How Can I rewrite my PHP script to use this user as authentication to run builds 如何重写我的PHP脚本以使用此用户作为身份验证来运行构建

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");

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. 如果您运行的jenkins版本大于1.426,则可以生成令牌以代替密码使用,这样就不会以纯文本形式显示密码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM