简体   繁体   English

无法使用蚂蚁运行jenkins job jenkins

[英]Can't run jenkins job jenkins using ant

I have some job in jenkins and i need start it using ant 我在詹金斯有一些工作,我需要用蚂蚁开始

ant run

Build.xml 在build.xml

<project name="jenkins-facade" default="run" basedir=".">
  <taskdef resource="net/sf/antcontrib/antlib.xml" />
  <description>
    simple example build file
  </description>
  <property name="post.json.encoded" value=""/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <property name="post.json" value='{"parameter": [{"name":"foo_param", "value":"123"}]}'/>
    <urlencode name="post.json.encoded" value="${post.json}" />
  </target>

  <target name="run" depends="init"
    description="run jenkins job">
    <post to = "http://jankhost:8080/job/Test/buildWithParameters/"
      verbose="true" failonerror="true">
      <prop name="token" value="1234567"/>
      <prop name="json" value="${post.json.encoded}"/>
    </post>
  </target>
</project>

But when i run it i got 403 error. 但是当我运行它时,我得到403错误。 I need to run a task on your behalf, and not by anonymous. 我需要代表您运行任务,而不是匿名运行。 How can i do this? 我怎样才能做到这一点? How to pass through the ant username and token? 如何通过ant用户名和令牌?

scr SCR

I'm surprised/horrified that there's an Ant task to do HTTP POST requests, but looking at its documentation , it appears that there's no way to set HTTP request headers, which you would need for a Jenkins API request like this. 我很惊讶/担心有一个Ant任务来执行HTTP POST请求,但是看看它的文档 ,似乎没有办法设置HTTP请求头,这对于像这样的Jenkins API请求是你需要的。

So as an alternative, you could try setting the username and API token in the URL — I don't know whether the Ant task supports this, but you could try http://<user>:<api_token>@jankhost:8080/job/Test/buildWithParameters/ 因此,您可以尝试在URL中设置用户名和API令牌 - 我不知道Ant任务是否支持此功能,但您可以尝试http://<user>:<api_token>@jankhost:8080/job/Test/buildWithParameters/

Another possibility, according to any https://<jenkins>/job/<name>/api page may be to use the secret token mechanism: 根据任何https://<jenkins>/job/<name>/api页面的另一种可能性可能是使用秘密令牌机制:

Another alternative (but deprecated) is to configure the 'Trigger builds remotely' section in the job configuration. 另一种替代方法(但已弃用)是在作业配置中配置“远程触发器构建”部分。 Then building or polling can be triggered by including a parameter called token in the request. 然后,可以通过在请求中包含名为token的参数来触发构建或轮询。

You can then include this secret token in the build URL itself. 然后,您可以在构建URL本身中包含此秘密令牌。 However, as you have security enabled, this will not work out-of-the-box — you will need to install the Build Token Root plugin, and follow the instructions there. 但是,当您启用了安全性时,这将无法开箱即用 - 您需要安装Build Token Root插件,并按照其中的说明进行操作。

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

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