-
Notifications
You must be signed in to change notification settings - Fork 118
Trigger command #1570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger command #1570
Changes from all commits
05f1257
69b36d8
74891cb
836cdca
8af71b6
1b48028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Lighthouse custome triggers | ||
|
||
You can enable use LH_CUSTOM_TRIGGER_COMMAND environment variable to add custom triggers. It takes in a comma seperated list of commands. | ||
|
||
When these commands are triggered using ChatOps, Lighthouse will store the command arg in TRIGGER_COMMAND_ARG PipelineRunPara which you can refer from the pipeline. | ||
|
||
eg: | ||
` | ||
LH_CUSTOM_TRIGGER_COMMAND=deploy,trigger | ||
` | ||
``` | ||
apiVersion: config.lighthouse.jenkins-x.io/v1alpha1 | ||
kind: TriggerConfig | ||
spec: | ||
presubmits: | ||
- name: pr | ||
context: "pr" | ||
always_run: true | ||
optional: false | ||
source: "pullrequest.yaml" | ||
- name: trigger | ||
context: "trigger" | ||
always_run: false | ||
optional: false | ||
rerun_command: /trigger this | ||
trigger: (?m)^/trigger( all| this),?(\s+|$) | ||
source: "trigger.yaml" | ||
- name: deploy | ||
context: "deployr" | ||
always_run: false | ||
optional: false | ||
rerun_command: /deploy dev | ||
trigger: (?m)^/deploy(?:[ \t]+([-\w]+(?:,[-\w]+)*))?(?:[ \t]+([-\w]+(?:,[-\w]+)*))? | ||
source: "deploy.yaml" | ||
postsubmits: | ||
- name: release | ||
context: "release" | ||
source: "release.yaml" | ||
branches: | ||
- ^main$ | ||
``` | ||
you can use ChatOps command to trigger each pipeline | ||
eg: | ||
***/deploy qa*** |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,23 +76,22 @@ var plugin = plugins.Plugin{ | |
} | ||
|
||
func init() { | ||
customTriggerCommand := os.Getenv(customerTriggerCommandEnvVar) | ||
if customTriggerCommand != "" { | ||
customCommand := plugins.Command{ | ||
Name: customTriggerCommand, | ||
Arg: &plugins.CommandArg{ | ||
Pattern: `[-\w]+(?:,[-\w]+)*`, | ||
}, | ||
Description: fmt.Sprintf("Manually trigger /%s chatops commands.", customTriggerCommand), | ||
Featured: true, | ||
Action: plugins. | ||
Invoke(handleGenericCommentEvent). | ||
When(plugins.Action(scm.ActionCreate), plugins.IsPR(), plugins.IssueState("open")), | ||
} | ||
plugin.Commands = append(plugin.Commands, customCommand) | ||
} | ||
|
||
plugins.RegisterPlugin(pluginName, plugin) | ||
customTriggerCommand := os.Getenv(customerTriggerCommandEnvVar) | ||
for _, trigger := range strings.Split(customTriggerCommand, ","){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you not already do this using a regex pattern for the customDeploymentTriggerCommand like: We are doing this currently to trigger builds with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree. This is interpreted as a regexp, so I think you should revert this change and update the documentation and tests accordingly. |
||
customCommand := plugins.Command{ | ||
Name: trigger, | ||
Arg: &plugins.CommandArg{ | ||
Pattern: `[-\w]+(?:,[-\w]+)*`, | ||
}, | ||
Description: fmt.Sprintf("Manually trigger /%s chatops commands.", trigger), | ||
Featured: true, | ||
Action: plugins. | ||
Invoke(handleGenericCommentEvent). | ||
When(plugins.Action(scm.ActionCreate), plugins.IsPR(), plugins.IssueState("open")), | ||
} | ||
plugin.Commands = append(plugin.Commands, customCommand) | ||
} | ||
plugins.RegisterPlugin(pluginName, plugin) | ||
} | ||
|
||
func configHelp(config *plugins.Configuration, enabledRepos []string) (map[string]string, error) { | ||
|
@@ -170,8 +169,8 @@ func handlePullRequest(pc plugins.Agent, pr scm.PullRequestHook) error { | |
return handlePR(getClient(pc), pc.PluginConfig.TriggerFor(org, repo), pr) | ||
} | ||
|
||
func handleGenericCommentEvent(_ plugins.CommandMatch, pc plugins.Agent, gc scmprovider.GenericCommentEvent) error { | ||
return handleGenericComment(getClient(pc), pc.PluginConfig.TriggerFor(gc.Repo.Namespace, gc.Repo.Name), gc) | ||
func handleGenericCommentEvent(cm plugins.CommandMatch, pc plugins.Agent, gc scmprovider.GenericCommentEvent) error { | ||
return handleGenericComment(getClient(pc), pc.PluginConfig.TriggerFor(gc.Repo.Namespace, gc.Repo.Name), gc, cm.Arg) | ||
} | ||
|
||
func handlePush(pc plugins.Agent, pe scm.PushHook) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature should be documented and unit test added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
836cdca adding in unit tests. please let me know if I have missed anything. I updated the code so that handleGenericComment take in the command arg.
documentation for this feature is in
lighthouse/docs/trigger/README.md
Line 5 in 1b48028