Skip to content

Commit

Permalink
Merge pull request mozilla-releng#352 from escapewindow/env-taskid
Browse files Browse the repository at this point in the history
add TASK_ID to task env.
  • Loading branch information
escapewindow committed Jun 26, 2019
2 parents fef50bb + 8d1d1b0 commit ee8d1ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [23.1.0] - 2019-06-26
### Added
- Added `context.task_id`

### Changed
- We now set `env['TASK_ID']` when running the script.

## [23.0.10] - 2019-06-11
### Fixed
- Fennec Beta cannot be shipped off mozilla-esr68
Expand Down
6 changes: 6 additions & 0 deletions scriptworker/context.py
Expand Up @@ -102,6 +102,12 @@ def credentials(self):
if self._credentials:
return dict(deepcopy(self._credentials))

@property
def task_id(self):
"""string: The running task's taskId."""
if self.claim_task:
return self.claim_task['status']['taskId']

@credentials.setter
def credentials(self, creds):
self._credentials = creds
Expand Down
5 changes: 4 additions & 1 deletion scriptworker/task.py
Expand Up @@ -530,7 +530,7 @@ def prepare_to_run_task(context, claim_task):
"""
current_task_info = {}
context.claim_task = claim_task
current_task_info['taskId'] = get_task_id(claim_task)
current_task_info['taskId'] = context.task_id
current_task_info['runId'] = get_run_id(claim_task)
log.info("Going to run taskId {taskId} runId {runId}!".format(
**current_task_info
Expand All @@ -556,12 +556,15 @@ async def run_task(context, to_cancellable_process):
int: exit code
"""
env = deepcopy(os.environ)
env['TASK_ID'] = context.task_id or 'None'
kwargs = { # pragma: no branch
'stdout': PIPE,
'stderr': PIPE,
'stdin': None,
'close_fds': True,
'preexec_fn': lambda: os.setsid(),
'env': env,
}

subprocess = await asyncio.create_subprocess_exec(*context.config['task_script'], **kwargs)
Expand Down

0 comments on commit ee8d1ab

Please sign in to comment.