简体   繁体   English

如果在第一个作业之后我们在控制台输出中获得特定值,如何在Jenkins中运行第二个作业

[英]How to run a second job in Jenkins if after the first job we got a specific value in console output

I'm new to Jenkins and have the follwing task. 我是詹金斯的新手并且完成了以下任务。 I'm trying to run a job when a condition is met, this condition will come from the console log. 我正在尝试在满足条件时运行作业,这种情况将来自控制台日志。

There is a method, in a first job, that outputs to console "Yes" or "No". 在第一个作业中,有一种方法输出到控制台“是”或“否”。 I need to parse this console output, get the value and if it is "Yes", I want to start the second job, if "No", don't start it. 我需要解析这个控制台输出,得到值,如果是“是”,我想开始第二个工作,如果“否”,不要启动它。

I've tried to search for jenkins plugins but there is nothing that fits my task or I just didn't find it. 我试图搜索jenkins插件,但没有任何东西适合我的任务或我只是没有找到它。

Can anyone give me advice or solutions: 任何人都可以给我建议或解决方案:

  1. To parse console output and get my param "Yes" or "No" 解析控制台输出并让我的参数“是”或“否”
  2. To run the second job if param is "Yes" 如果param是“是”,则运行第二个作业

Thanks! 谢谢!

You can trigger a job using the Remote access API 您可以使用远程访问API触发作业

Remote API can be used to do things like these: 远程API可用于执行以下操作:

  1. retrieve information from Jenkins for programmatic consumption. 从Jenkins检索信息以供程序化使用。

  2. trigger a new build 触发新构建

  3. create/copy jobs 创建/复制工作

You could have a groovy step in your first job which follows this approach to trigger a job on your condition 你可以在你的第一份工作中采用一种常规步骤,按照这种方法来触发你的工作

def list = manager.build.logFile.readLines()
def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")} 

And to call an end point in groovy this is all you need 在groovy中称呼这个终点,这就是你所需要的

def html = "http://google.com".toURL().text

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

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