-
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 3 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 convert the command arg into TRIGGER_COMMAND_ARG enviroment variable 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 | ||
---|---|---|---|---|
|
@@ -30,7 +30,11 @@ import ( | |||
"k8s.io/apimachinery/pkg/util/sets" | ||||
) | ||||
|
||||
func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.GenericCommentEvent) error { | ||||
func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.GenericCommentEvent) error{ | ||||
return handleGenericCommentWithArg(c, trigger, gc, "") | ||||
|
||||
} | ||||
func handleGenericCommentWithArg(c Client, trigger *plugins.Trigger, gc scmprovider.GenericCommentEvent, arg string) error { | ||||
org := gc.Repo.Namespace | ||||
repo := gc.Repo.Name | ||||
number := gc.Number | ||||
|
@@ -94,6 +98,14 @@ func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.Gen | |||
if err != nil { | ||||
return err | ||||
} | ||||
if arg != "" { | ||||
for i := range toTest { | ||||
toTest[i].Base.PipelineRunParams = append(toTest[i].Base.PipelineRunParams , job.PipelineRunParam{ | ||||
Name: "TRIGGER_COMMAND_ARG", | ||||
ValueTemplate: arg, | ||||
}) | ||||
} | ||||
} | ||||
Comment on lines
+97
to
+104
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. The feature should be documented and unit test added 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. 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. lighthouse/docs/trigger/README.md Line 5 in 1b48028
|
||||
return RunAndSkipJobs(c, pr, toTest, toSkip, gc.GUID, trigger.ElideSkippedContexts) | ||||
} | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,13 +77,13 @@ var plugin = plugins.Plugin{ | |
|
||
func init() { | ||
customTriggerCommand := os.Getenv(customerTriggerCommandEnvVar) | ||
if customTriggerCommand != "" { | ||
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: customTriggerCommand, | ||
Name: trigger, | ||
Arg: &plugins.CommandArg{ | ||
Pattern: `[-\w]+(?:,[-\w]+)*`, | ||
}, | ||
Description: fmt.Sprintf("Manually trigger /%s chatops commands.", customTriggerCommand), | ||
Description: fmt.Sprintf("Manually trigger /%s chatops commands.", trigger), | ||
Featured: true, | ||
Action: plugins. | ||
Invoke(handleGenericCommentEvent). | ||
|
@@ -170,8 +170,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 handleGenericCommentWithArg(getClient(pc), pc.PluginConfig.TriggerFor(gc.Repo.Namespace, gc.Repo.Name), gc, cm.Arg) | ||
} | ||
|
||
func handlePush(pc plugins.Agent, pe scm.PushHook) error { | ||
|
Uh oh!
There was an error while loading. Please reload this page.