trigger other configuration and send current build

2019-07-16 16:09发布

In a certain Jenkins config, I wish to trigger another configuration as post build action. I want to pass as one of the parameters the current build status.

IE: a string / int that represents the status (SUCCESS/FAIL/UNSTABLE).

I have 2 options to create post build triggers:

Using the join plugin join plug-in

Using the trigger parameterized build in post build actions parameterized build

I wish there was some kind of accessible env variable at end of run...

Have any idea?

Thanks!

2条回答
疯言疯语
2楼-- · 2019-07-16 17:01

You can check for status using Groovy script in post-build step via Groovy Post-Build plugin that can access Jenkins internals via Jenkins Java API. The plugin provides the script with variable manager that can be used to access important parts of the API (see Usage section in the plugin documentation).

For example, this is how you can output build result to build console:

def result = manager.build.result
manager.listener.logger.println "And the result is: ${result}"

Now, you can instead use that value to create a properties file and pass that file to Parameterized Trigger post-build step (it has such an option).

One caveat: I am not sure if it is possible to arrange post-build steps to execute in a particular order to ensure that Groovy post-build step runs before the Parameterized Trigger step.

查看更多
来,给爷笑一个
3楼-- · 2019-07-16 17:03

Here is a simple solution that will answer most cases:

Use 'Trigger Parameterized Build' plugin, and set two triggers -

  1. 'Stable or unstable but not fail'
  2. 'Fail'

Each of those triggers should run the same job - let's call it 'JOB_B'.

For each of the triggers, pass whatever parameters you like, and also pass a user-defined value:

  • for trigger '1' use: JOB_A_STATUS=SUCCESS
  • for trigger '2' use: JOB_A_STATUS=FAIL

Now, all you need to do is test the value of ${JOB_A_STATUS} from JOB_B, to see if it is set to 'SUCCESS' or 'FAIL'.

Note this solution does not distinguish between 'stable' and 'unstable', but only knows the difference between 'fail' and 'success'.

Good luck!

查看更多
登录 后发表回答