将结果从Parameterized Trigger插件传回 [英] Passing the result back from Parameterized Trigger plugin

查看:330
本文介绍了将结果从Parameterized Trigger插件传回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个工作:助手"和主",以及单个jenkins实例(它是主机和执行者).

I have 2 jobs: "Helper" and "Main" and the single jenkins instance (which is the host and the executor).

帮助程序管理第三方资源并为Main作业做准备(准确地说,它为要部署用于测试的应用程序创建了环境).

The helper manages 3rd party resource and makes the preparation for the Main job (to be precise - it creates the environment for the application to be deployed for testing).

帮助程序作业的唯一工件是单个文件,该文件具有专门为主要作业准备的环境IP.

The only artifact for the helper job is a single file with IP of the environment prepared especially for the Main job.

在这种情况下,我如何将构建版本从帮助程序传递回主程序?

How would I pass back the build from the Helper to the Main in this case?

推荐答案

您说的是,只需要将带有IP的文件传递给主"作业即可.如果您只需要该IP,那么有更简便的方法(没有文件),我将同时介绍这两种方法.

You are saying that you only need to pass a file with an IP to the "Main" job. If all you need is that IP, there are easier ways of doing it (without files), I will describe both.

在助手"作业中,您需要从工作区中存档该文件.

In the "Helper" job, you need to archive that file from your workspace.

  1. 构建后操作中,选择存档工件
  2. 放置相对于工作空间的路径.您可以使用通配符,或者如果文件名始终相同,则可以对其进行硬编码.
  3. 使用在其他项目上进行的触发/调用构建,将该任务配置为自动触发您的主要"任务.如果您没有此插件,则可以在此处
  4. 进行获取.
  5. 要构建的项目,请输入主要"工作的名称
  1. In post-build actions, choose Archive the artifacts
  2. Put a path relative to the workspace. You can use wildcards, or hardcode the name of the file if it is always same.
  3. Configure this job to automatically trigger your "Main" job using Trigger/Call builds on other projects build step. If you don't have this plugin, you can get it here
  4. For Projects to build, enter the name of your "Main" job

现在,在主"作业中,您需要从上一个(助手")作业中复制此工件.

Now, in the "Main" job, you need to copy this artifact from the previous ("Helper") job.

  1. 对于第一个构建步骤,请选择从另一个项目复制工件构建步骤.如果您没有此插件,则可以在此处
  2. 获得
  3. 对于项目名称,请输入您的助手"作业的名称
  4. 对于哪个版本,请选择最新成功版本
  5. 要复制的工件,请使用**/yourartifactname*.*.您的工件名称将是您在助手"作业中配置的名称.在前面使用**/可以确保在进入工件之前它将忽略任何目录结构
  6. 对于目标目录,在主"作业的工作区中指定一个位置,也要复制此文件.
  7. 选中 Flatten目录,因此文件将直接转到第5步中指定的位置,否则它将保留在(帮助"作业中)归档的目录结构.
  1. For the first build step, select Copy artifacts from another project build step. If you don't have this plugin, you can get it here
  2. For the Project name, enter the name of your "Helper" job
  3. For Which build, select Latest successful build
  4. For Artifacts to copy, use **/yourartifactname*.* Your artifact name will be what you configured in "Helper" job. Using **/ in front makes sure it will ignore any directory structure before getting to the artifact
  5. For, Target directory, specify a location in your "Main" job's workspace where this file will be copied too.
  6. Checkmark Flatten directories, so the file goes directly to the location specified in Step 5, else it will retain the directory structure that it was archived under (in "Helper" job)

现在,您的主"作业在其工作区中具有助手"作业的文件.像使用工作区中的任何其他文件一样使用它

Now, your "Main" job has the file from "Helper" job in it's workspace. Use it like you would any other file in your workspace

就像我提到的那样,如果您只需要一个IP地址,并且在"Helper"作业中某个时间点将其作为变量,则只需使用 Trigger/在帮助程序"作业的第3步和第4步中配置的其他项目上构建呼叫.在这种情况下,您不需要在主要"作业上进行任何特殊配置.

Like I mentioned, if all you need is that one IP address, that you have as a variable at one point in time in "Helper" job, you just send it to "Main" job using the Trigger/Call builds on other projects step that you configured in steps 3 and 4 of the "Helper" job. In this case, you don't need any special configuration on "Main" job.

  1. 使用"在其他项目上构建的触发器/调用" 构建步骤,配置"Helper"任务以自动触发您的"Main"任务.如果您没有此插件,则可以在此处
  2. 进行获取.
  3. 要构建的项目,请输入主要"工作的名称
  4. 点击添加参数按钮
  5. 选择预定义参数
  6. 键入VarForMain=$VarFromHelper,其中VarFromHelper是包含IP地址的帮助程序"作业中的环境变量,而VarForMain是将在主"作业中设置为该值的环境变量.没有理由不能使用相同的名称.
  1. Configure "Helper" job to automatically trigger your "Main" job using Trigger/Call builds on other projects build step. If you don't have this plugin, you can get it here
  2. For Projects to build, enter the name of your "Main" job
  3. Click Add Parameters button
  4. Select Predefined parameters
  5. Type VarForMain=$VarFromHelper, where VarFromHelper is your environment variable from the "Helper" job that contains your IP address, and VarForMain is the environment variable that will be set in your "Main" job to this value. There is no reason why these can't have the same name.

现在,在主"作业中,您可以像引用任何其他环境变量一样引用$VarForMain

Now, in your "Main" job, you can reference $VarForMain as you would any other environment variable

这篇关于将结果从Parameterized Trigger插件传回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆