简体   繁体   English

使用 API/Actions Pluginfor Jenkins 从 Jenkins 管道触发 GitHub 操作

[英]Trigger GitHub Actions from Jenkins Pipeline using API/Actions Pluginfor Jenkins

I want to trigger the GitHub Actions using Jenkins Pipeline or Jenkins Job and send some build parameters as input for the GitHub Actions.我想使用 Jenkins 管道或 Jenkins 作业触发 GitHub 操作,并发送一些构建参数作为 GitHub 操作的输入。 I am doing this since there is no option of dropdown list for the GitHub Action Input parameters.我这样做是因为 GitHub 操作输入参数没有下拉列表选项。

This is only half a solution.这只是解决方案的一半。 But there is an option to specify an input params list for GitHub actions.但是一个选项可以为 GitHub 操作指定输入参数列表。

See workflow_dispatch event type on GitHub actions.请参阅 GitHub 操作上的workflow_dispatch事件类型。 The current url is here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch (If this stops working just google workflow_dispatch)当前的 url 在这里: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch (如果这停止工作只是谷歌 workflow_dispatch)

The other half (Jenkins triggering a GHA build), I am actually searching for myself too.另一半(Jenkins 触发 GHA 构建),我实际上也在寻找自己。 I can find ones working in reverse.我可以找到反向工作的。 GHA triggering jenkins. GHA 触发詹金斯。

We can trigger Github action with rest api (POST) or curl requests.我们可以通过 rest api (POST) 或 curl 请求触发 Github 操作。 All you need to do create with workflow with dispatch trigger (repository_dispatch or workflow_dispatch)您需要做的就是使用带有调度触发器的工作流创建(repository_dispatch 或 workflow_dispatch)

on:
  workflow_dispatch:
    inputs:
      InputKey:
        type: string
        required: true

next trigger this workflow by one of the below methods接下来通过以下方法之一触发此工作流

1. POST https://api.github.com/repos/ //dispatches Authorization: Bearer 1. POST https://api.github.com/repos/ //dispatches Authorization: Bearer

{"event_type": "hello"}
  1. curl --request POST curl——请求POST
    --url 'https://api.github.com/repos///dispatches' --url 'https://api.github.com/repos///dispatches'
    --header 'authorization: Bearer ' --header '授权:Bearer '
    --data '{"event_type": "hello"}' --data '{"event_type": "hello"}'

Also specify the inputs in requests with --data '{"event_type": "<workflow name>","client_payload":{"<input_key>":"<input_value>"}}'还使用--data '{"event_type": "<workflow name>","client_payload":{"<input_key>":"<input_value>"}}'指定请求中的输入

All you need to do now is put this request in your job (scripted pipeline is preferred) with appropriate values.您现在需要做的就是将此请求以适当的值放入您的工作中(首选脚本管道)。

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

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