如何通过外部Perl脚本触发Jenkins构建

如何通过外部Perl脚本触发Jenkins构建

本文介绍了如何通过外部Perl脚本触发Jenkins构建/作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在Unix环境中编写一个Perl脚本,该脚本通过传递Jenkins master的URL和其他参数来触发Jenkins构建/作业.该怎么办?

I aiming to write a Perl script in a Unix environment which triggers a Jenkins build/job by passing the URL for the Jenkins master and other parameters.How could this be done?

以下是我的一些详细问题:

Here are some detailed questions I had:

  • 我需要什么Perl库?
  • Perl需要哪些功能?
  • 如何从脚本中将其他构建参数传递给Jenkins?
  • 如何从詹金斯那里得到结果?

推荐答案

您通常需要 LWP 模块及其子模块. 这里是有关如何使用它的文章:

You would normally need the LWP module and maybe its sub modules. Here's an article on how you'd use it:

我通常是会说"在可以使用Perl解决方案时不使用system "的人.

I am normally the person who will say "Don't use system when you can use a Perl solution".

但是,在这种情况下,我将作为一个例外,因为只需要对 wget 命令:

However, I will make an exception in this case since it is way easier just to make that one system call to the wget command:

system qq(wget -q $build_trigger_url);

如何从脚本中将其他构建参数传递给Jenkins?

要将参数传递给Jenkins构建,将涉及通过修改%ENV哈希值或通过将URL修改为包括这些参数(通过GET请求)来设置环境变量.不同的插件和配置需要不同的方式来实现.

How can to pass other build parameters to Jenkins from the script?

To pass parameters to the Jenkins build will involve either setting environment variables by modifying the %ENV hash, or by modifying the URL to include these parameters (via a GET request). Different plugins and configurations require different ways of doing this.

如果您的构建计算机是Windows系统,则可以下载 wget 命令

If your build machine is a Windows system, you can download the wget command.

Jenkins具有内置的RESTful API.只需单击每页底部的 REST API 链接.您可以使用 REST :: Client 模块进行REST调用,但您也可以仅使用system调用wget.

Jenkins has a built-in RESTful API. Just click the REST API links that are on the bottom of each page. You can use the REST::Client module to make REST calls, but you can also just use system calls to wget too.

RESTful API将以JSON或XML格式返回数据.您应该获得一个JSON或XML模块来帮助读取此数据.有时候,RESTful API会返回纯文本,例如在获取最新的内部版本号或时间戳时.

The RESTful API will return data in either JSON or XML format. You should get a JSON or XML module to help read this data. Sometimes, the RESTful API will return plain text like when getting the latest build number or timestamp.

这篇关于如何通过外部Perl脚本触发Jenkins构建/作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:05