-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1563 from jenkins-x/newtriggers
feat: trigger on deploy status and periodically
- Loading branch information
Showing
29 changed files
with
1,226 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package job | ||
|
||
type Deployment struct { | ||
Base | ||
Reporter | ||
// The deployment state that trigger this pipeline | ||
// Can be one of: error, failure, inactive, in_progress, queued, pending, success | ||
// If not set all deployment state event triggers | ||
State string `json:"state,omitempty"` | ||
// Deployment for this environment trigger this pipeline | ||
// If not set deployments for all environments trigger | ||
Environment string `json:"environment,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package trigger | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/jenkins-x/go-scm/scm" | ||
"github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1" | ||
"github.com/jenkins-x/lighthouse/pkg/jobutil" | ||
"github.com/jenkins-x/lighthouse/pkg/scmprovider" | ||
) | ||
|
||
func handleDeployment(c Client, ds scm.DeploymentStatusHook) error { | ||
for _, j := range c.Config.GetDeployments(ds.Repo) { | ||
if j.State != "" && j.State != ds.DeploymentStatus.State { | ||
continue | ||
} | ||
if j.Environment != "" && !strings.EqualFold(j.Environment, ds.Deployment.Environment) { | ||
continue | ||
} | ||
labels := make(map[string]string) | ||
for k, v := range j.Labels { | ||
labels[k] = v | ||
} | ||
refs := v1alpha1.Refs{ | ||
Org: ds.Repo.Namespace, | ||
Repo: ds.Repo.Name, | ||
BaseRef: ds.Deployment.Ref, | ||
BaseSHA: ds.Deployment.Sha, | ||
BaseLink: ds.Deployment.RepositoryLink, | ||
CloneURI: ds.Repo.Clone, | ||
} | ||
labels[scmprovider.EventGUID] = ds.DeploymentStatus.ID | ||
pj := jobutil.NewLighthouseJob(jobutil.DeploymentSpec(c.Logger, j, refs), labels, j.Annotations) | ||
c.Logger.WithFields(jobutil.LighthouseJobFields(&pj)).Info("Creating a new LighthouseJob.") | ||
lj, err := c.LauncherClient.Launch(&pj) | ||
if err != nil { | ||
return err | ||
} | ||
c.Logger.WithFields(jobutil.LighthouseJobFields(lj)).Debug("LighthouseJob created") | ||
} | ||
return nil | ||
} |
Oops, something went wrong.