ci: support jobs which don’t run unless triggered by name
By default, any job will run unless a filter is given, in that case the filter will determine if the job should run or not. Some jobs do not need to be run by default, and should only be triggered using the bot. For such jobs, BOT_NEEDS_TRIGGER_BY_NAME can added to environment variables.
This commit is contained in:
parent
88d0d6ffb0
commit
9d0751e2b1
1 changed files with 8 additions and 4 deletions
|
@ -28,8 +28,8 @@ def parse_filter(filter_name):
|
||||||
return filters
|
return filters
|
||||||
|
|
||||||
|
|
||||||
def process_filter(filter_name, ci_name):
|
def process_filter(execute_by_default, filter_name, ci_name):
|
||||||
execute = True
|
execute = execute_by_default
|
||||||
|
|
||||||
# bot message is case insensitive (processed with lower case). so we also convert ci_name to lower case.
|
# bot message is case insensitive (processed with lower case). so we also convert ci_name to lower case.
|
||||||
ci_name = ci_name.lower()
|
ci_name = ci_name.lower()
|
||||||
|
@ -51,8 +51,12 @@ def process_filter(filter_name, ci_name):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
need_to_execute = process_filter("BOT_STAGE_FILTER", os.getenv("CI_JOB_STAGE")) \
|
execute_by_default = True
|
||||||
and process_filter("BOT_JOB_FILTER", os.getenv("CI_JOB_NAME"))
|
if os.getenv("BOT_NEEDS_TRIGGER_BY_NAME", "0") == "1":
|
||||||
|
execute_by_default = False
|
||||||
|
|
||||||
|
need_to_execute = process_filter(True, "BOT_STAGE_FILTER", os.getenv("CI_JOB_STAGE")) \
|
||||||
|
and process_filter(execute_by_default, "BOT_JOB_FILTER", os.getenv("CI_JOB_NAME"))
|
||||||
if need_to_execute:
|
if need_to_execute:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue