actions / actions/runner

ACTIONS_RUNNER_HOOK_JOB_COMPLETED not able to remove workspace

Open
#2,154 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
6.3k
Forks
1.4k
Avg merge
1d 16h
Merged PRs (30d)
24

Description

Describe the bug

Using a simple workflow which just checks out the repository

name: JCO

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: [self-hosted, windows]
    steps: 
      - uses: actions/checkout@v2

a simple powershell script

$time_to_wait = 30
Write-Output "Wait '${time_to_wait}' seconds for the file system to become unlocked."
Start-Sleep -Seconds $time_to_wait
Remove-Item "${env:GITHUB_WORKSPACE}" -Recurse -WhatIf
Remove-Item "${env:RUNNER_WORKSPACE}" -Recurse -WhatIf

called with ACTIONS_RUNNER_HOOK_JOB_COMPLETED is not able to remove neither GITHUB_WORKSPACE nor RUNNER_WORKSPACE.

Runner Version and Platform

Version of your runner?

2.296.2

OS of the machine running the runner? OSX/Windows/Linux/...

Windows

What's not working?

From documentation I would expect to be able to wipeout the workspace at the end of the run but the Remove-Item command tells me, the directory is locked.

Job Log Output

A job completed hook has been configured by the self-hosted runner administrator
Run '<path to>\sample_cleanup.ps1'
shell: C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"
Wait '30' seconds for the file system to become unlocked.
Remove-Item : Cannot remove the item at 'C:\github_work\<repository name>\<repository name>'
because it is in use.
At <path to>\sample_cleanup.ps1:4 char:1

  • Remove-Item "${env:GITHUB_WORKSPACE}" -Recurse -WhatIf
  •   + CategoryInfo          : InvalidOperation: (:) [Remove-Item], PSInvalidOperationException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemoveItemCommand
    
    

Remove-Item : Cannot remove the item at 'C:\github_work\<repository name>' because it is in use.
At <path to>\sample_cleanup.ps1:5 char:1

  • Remove-Item "${env:RUNNER_WORKSPACE}" -Recurse -WhatIf
  •   + CategoryInfo          : InvalidOperation: (:) [Remove-Item], PSInvalidOperationException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemoveItemCommand
    

Runner and Worker's Diagnostic Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Windows self-hosted runner workflow with runner version 2.296.2 and the ACTIONS_RUNNER_HOOK_JOB_COMPLETED PowerShell script shown in the issue. Start by tracing the job-completed hook lifecycle and workspace cleanup behavior; done means determining why GITHUB_WORKSPACE and RUNNER_WORKSPACE remain locked and verifying the documented cleanup expectation.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, powershell
Domain
ci-cd, devops, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.