Skip to content

Commit e800414

Browse files
committed
feat: expose RUN_ID and TASKCLUSTER_ROOT_URL to scriptworkers
This will be needed to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1967787.
1 parent 89ce7f6 commit e800414

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/scriptworker/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ async def run_task(context, to_cancellable_process):
657657
"""
658658
env = deepcopy(os.environ)
659659
env["TASK_ID"] = context.task_id or "None"
660+
env["RUN_ID"] = get_run_id(context.claim_task)
661+
env["TASKCLUSTER_ROOT_URL"] = context.config["taskcluster_root_url"]
660662
kwargs = {"stdout": PIPE, "stderr": PIPE, "stdin": None, "close_fds": True, "preexec_fn": lambda: os.setsid(), "env": env} # pragma: no branch
661663

662664
subprocess = await asyncio.create_subprocess_exec(*context.config["task_script"], **kwargs)

tests/test_task.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def mobile_context(mobile_rw_context):
4141
def _craft_context(rw_context):
4242
rw_context.config["reclaim_interval"] = 0.001
4343
rw_context.config["task_max_timeout"] = 1
44-
rw_context.config["task_script"] = ("bash", "-c", ">&2 echo bar && echo foo && exit 1")
44+
rw_context.config["taskcluster_root_url"] = "https://tc"
45+
rw_context.config["task_script"] = ("bash", "-c", ">&2 echo $TASK_ID && echo $RUN_ID && echo $TASKCLUSTER_ROOT_URL && exit 1")
4546
rw_context.claim_task = {
4647
"credentials": {"a": "b"},
4748
"status": {"taskId": "taskId"},
@@ -496,7 +497,7 @@ def test_prepare_to_run_task(context):
496497
async def test_run_task(context):
497498
status = await swtask.run_task(context, noop_to_cancellable_process)
498499
log_file = log.get_log_filename(context)
499-
assert read(log_file) in ("bar\nfoo\nexit code: 1\n", "foo\nbar\nexit code: 1\n")
500+
assert read(log_file) in ("taskId\nrunId\nhttps://tc\nexit code: 1\n", "taskId\nrunId\nhttps://tc\nexit code: 1\n")
500501
assert status == 1
501502

502503

tests/test_worker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
# constants helpers and fixtures {{{1
2626
@pytest.fixture(scope="function")
2727
def context(rw_context):
28+
rw_context.config["taskcluster_root_url"] = "https://tc"
2829
rw_context.credentials_timestamp = arrow.utcnow().shift(minutes=-10).int_timestamp
30+
rw_context.claim_task = {
31+
"credentials": {"a": "b"},
32+
"status": {"taskId": "taskId"},
33+
"task": {"dependencies": ["dependency1", "dependency2"], "taskGroupId": "dependency0"},
34+
"runId": "runId",
35+
}
2936
yield rw_context
3037

3138

0 commit comments

Comments
 (0)