Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to Dynamically Obtain User Profile Path in Self hosted Windows Agent for Bitbucket Pipelines

Gajesh Bhat July 4, 2024

Hello everyone,

I'm running a pipeline on a Self hosted Windows runner in Bitbucket Pipelines and need to clean the temporary files located in atlassian_runners\atlassian-bitbucket-pipelines-runner\temp\*  as not doing that while running docker containers in windows using the runner will move the runner into unhealthy state. (I have built my own wrapper around the self hosted windows runner as Windows Docker Runners aren't supported in Bitbucket Pipelines yet).  See my other question for more hints on how I am doing it.  https://community.atlassian.com/t5/Bitbucket-questions/Issues-running-Windows-Docker-Container-on-Pipelines-Self-hosted/qaq-p/2735498 However, I'm struggling to dynamically obtain the user profile path. My goal is to avoid hardcoding the user profile path and handle it dynamically within the script.

Here's what I've tried so far:

  1. Using [System.Environment]::GetFolderPath('UserProfile')

     $UserProfile = [System.Environment]::GetFolderPath('UserProfile')
  2. $TempPath = "$UserProfile\atlassian_runners\atlassian-bitbucket-pipelines-runner\temp\*"
  3. Remove-Item -Path $TempPath -Recurse -Force

This returns the system profile path (C:\Windows\system32\config\systemprofile) instead of the intended user profile path. It seems that the script runs under a different context (Possibly in a Sandboxed JVM environment) in the Bitbucket pipeline.

Questions:

  1. How can I reliably obtain the user profile path dynamically in a Bitbucket pipeline running on a Windows agent?
  2. Is there a known issue with the Windows agent in Bitbucket Pipelines that affects retrieving the user profile path?
  3. Are there any best practices or alternative methods to achieve this?

Any help or guidance would be greatly appreciated!

Regards,

Gajesh

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events