Skip to content

Enhancement: Allow combining run_if_changed and skip_if_only_changed for more flexible job triggering #502

@kaovilai

Description

@kaovilai

Summary

Currently, run_if_changed and skip_if_only_changed are mutually exclusive in job configuration, enforced by validation in the validateTriggering function. This limitation prevents users from creating more sophisticated job triggering logic that could benefit from combining both conditions.

Current Implementation

As of commit 419f5e43, the validation in pkg/config/config.go prevents jobs from specifying both fields:

if job.RunIfChanged != "" && job.SkipIfOnlyChanged != "" {
    return fmt.Errorf("job %s declares run_if_changed and skip_if_only_changed, which are mutually exclusive", job.Name)
}

Motivation and Use Case

There are legitimate scenarios where combining both conditions would provide more precise control over job execution:

Example Scenario: A comprehensive test suite that should:

  • Run when core application files change (run_if_changed: "^(src/|tests/)")
  • BUT skip when only documentation files change (skip_if_only_changed: "^docs/")

Current Workaround Limitations:

  • Using only run_if_changed cannot exclude documentation-only changes
  • Using only skip_if_only_changed cannot ensure the job runs for specific critical paths
  • Complex regex patterns become unwieldy and hard to maintain

Proposed Enhancement

Remove the mutual exclusivity constraint and implement combined logic where:

  1. Both conditions must be satisfied for the job to run:

    • At least one changed file matches run_if_changed pattern
    • AND NOT all changed files match skip_if_only_changed pattern
  2. Logical precedence:

    • If run_if_changed is specified, at least one file must match it
    • If skip_if_only_changed is specified, not all files should match it
    • Both conditions are evaluated independently and combined with AND logic

Implementation Considerations

The change would involve:

  1. Remove validation constraint in validateTriggering function
  2. Update job execution logic in RegexpChangeMatcher methods to handle both conditions
  3. Maintain backward compatibility - existing configurations with only one field should continue working unchanged
  4. Add comprehensive tests for the combined logic scenarios

Benefits

  • More granular control over job triggering based on file changes
  • Reduced CI resource usage by avoiding unnecessary job runs
  • Simplified configuration compared to complex single-regex solutions
  • Better developer experience with more intuitive job triggering rules

Backward Compatibility

This change is fully backward compatible as it only removes a restriction. Existing jobs using either run_if_changed or skip_if_only_changed individually will continue to work exactly as before.

Related Work

This enhancement addresses similar needs discussed in issue #151 where users wanted more precise control over when jobs run based on file changes, particularly for skipping CI when only documentation changes are present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/pluginsIssues or PRs related to prow's plugins for the hook componentkind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions