mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 18:01:02 +00:00
Fix pipeline-related environment (#2876)
closes https://github.com/woodpecker-ci/woodpecker/issues/2672 pipeline model must be persisted first to have some fields like `Number` and `ID`
This commit is contained in:
parent
b31b3e9a86
commit
849b02a433
1 changed files with 11 additions and 13 deletions
|
@ -54,6 +54,13 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
|
|||
// update some pipeline fields
|
||||
pipeline.RepoID = repo.ID
|
||||
pipeline.Status = model.StatusPending
|
||||
setGatedState(repo, pipeline)
|
||||
err = _store.CreatePipeline(pipeline)
|
||||
if err != nil {
|
||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
||||
log.Error().Str("repo", repo.FullName).Err(err).Msg(msg.Error())
|
||||
return nil, msg
|
||||
}
|
||||
|
||||
// fetch the pipeline file from the forge
|
||||
configFetcher := forge.NewConfigFetcher(server.Config.Services.Forge, server.Config.Services.Timeout, server.Config.Services.ConfigService, repoUser, repo, pipeline)
|
||||
|
@ -61,13 +68,13 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
|
|||
|
||||
if configFetchErr != nil {
|
||||
log.Debug().Str("repo", repo.FullName).Err(configFetchErr).Msgf("cannot find config '%s' in '%s' with user: '%s'", repo.Config, pipeline.Ref, repoUser.Login)
|
||||
return nil, persistPipelineWithErr(ctx, _store, pipeline, repo, repoUser, fmt.Errorf("pipeline definition not found in %s", repo.FullName))
|
||||
return nil, updatePipelineWithErr(ctx, _store, pipeline, repo, repoUser, fmt.Errorf("pipeline definition not found in %s", repo.FullName))
|
||||
}
|
||||
|
||||
pipelineItems, parseErr := parsePipeline(_store, pipeline, repoUser, repo, forgeYamlConfigs, nil)
|
||||
if errors.HasBlockingErrors(parseErr) {
|
||||
log.Debug().Str("repo", repo.FullName).Err(parseErr).Msg("failed to parse yaml")
|
||||
return nil, persistPipelineWithErr(ctx, _store, pipeline, repo, repoUser, parseErr)
|
||||
return nil, updatePipelineWithErr(ctx, _store, pipeline, repo, repoUser, parseErr)
|
||||
} else if parseErr != nil {
|
||||
pipeline.Errors = errors.GetPipelineErrors(parseErr)
|
||||
}
|
||||
|
@ -77,15 +84,6 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
|
|||
return nil, ErrFiltered
|
||||
}
|
||||
|
||||
setGatedState(repo, pipeline)
|
||||
|
||||
err = _store.CreatePipeline(pipeline)
|
||||
if err != nil {
|
||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
||||
log.Error().Str("repo", repo.FullName).Err(err).Msg(msg.Error())
|
||||
return nil, msg
|
||||
}
|
||||
|
||||
pipeline = setPipelineStepsOnPipeline(pipeline, pipelineItems)
|
||||
|
||||
// persist the pipeline config for historical correctness, restarts, etc
|
||||
|
@ -121,12 +119,12 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
|
|||
return pipeline, nil
|
||||
}
|
||||
|
||||
func persistPipelineWithErr(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User, err error) error {
|
||||
func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User, err error) error {
|
||||
pipeline.Started = time.Now().Unix()
|
||||
pipeline.Finished = pipeline.Started
|
||||
pipeline.Status = model.StatusError
|
||||
pipeline.Errors = errors.GetPipelineErrors(err)
|
||||
dbErr := _store.CreatePipeline(pipeline)
|
||||
dbErr := _store.UpdatePipeline(pipeline)
|
||||
if dbErr != nil {
|
||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
||||
log.Error().Err(dbErr).Msg(msg.Error())
|
||||
|
|
Loading…
Reference in a new issue