diff --git a/pipeline/frontend/yaml/constraint/constraint.go b/pipeline/frontend/yaml/constraint/constraint.go index 16cdb1ca5..ab5cde410 100644 --- a/pipeline/frontend/yaml/constraint/constraint.go +++ b/pipeline/frontend/yaml/constraint/constraint.go @@ -19,20 +19,16 @@ import ( "fmt" "maps" "path" - "regexp" "strings" "github.com/antonmedv/expr" "github.com/bmatcuk/doublestar/v4" - "github.com/rs/zerolog/log" "gopkg.in/yaml.v3" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata" yamlBaseTypes "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base" ) -var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) - type ( // When defines a set of runtime constraints. When struct { @@ -82,16 +78,6 @@ func (when *When) IsEmpty() bool { // Returns true if at least one of the internal constraints is true. func (when *When) Match(metadata metadata.Metadata, global bool, env map[string]string) (bool, error) { - if global { - // skip the whole workflow if any case-insensitive combination of the words "skip" and "ci" - // wrapped in square brackets appear in the commit message - skipMatch := skipRe.FindString(metadata.Curr.Commit.Message) - if len(skipMatch) > 0 { - log.Debug().Msgf("skip workflow as keyword to do so was detected in commit message '%s'", metadata.Curr.Commit.Message) - return false, nil - } - } - for _, c := range when.Constraints { match, err := c.Match(metadata, global, env) if err != nil { diff --git a/server/pipeline/create.go b/server/pipeline/create.go index 99ac34d3a..8c143a27b 100644 --- a/server/pipeline/create.go +++ b/server/pipeline/create.go @@ -17,6 +17,7 @@ package pipeline import ( "context" "fmt" + "regexp" "time" "github.com/rs/zerolog/log" @@ -27,6 +28,8 @@ import ( "github.com/woodpecker-ci/woodpecker/server/store" ) +var skipPipelineRegex = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) + // Create a new pipeline and start it func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline *model.Pipeline) (*model.Pipeline, error) { repoUser, err := _store.GetUser(repo.UserID) @@ -36,6 +39,12 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline return nil, fmt.Errorf(msg) } + skipMatch := skipPipelineRegex.FindString(pipeline.Message) + if len(skipMatch) > 0 { + log.Debug().Str("repo", repo.FullName).Msgf("ignoring pipeline as skip-ci was found in the commit (%s) message '%s'", pipeline.Commit, pipeline.Message) + return nil, ErrFiltered + } + // If the forge has a refresh token, the current access token // may be stale. Therefore, we should refresh prior to dispatching // the pipeline.