Use working-directory for entire job #25742
-
Is it possible to specify a |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 14 replies
-
When you use jobs.<job_id>.steps.run , using the working-directory keyword, you can specify the working directory of where to run the command. You need to add work-directory keyword to all jobs.<job_id>.steps.run. Please refer to this document for more details. If you want to use working-directory for entire job, I would suggest to set a job level environment variable, set its value with the directory, and then use context with ${{ env.variablename}} as the value of work-directory keyword in jobs.<job_id>.steps.run. For Contexts syntax for GitHub Actions , please refer to: Please see my example, my repo file structure is like this: I add a job level env named “working-directory”. Then set ${{env.working-directory}} as the value of working-directory keyword in jobs.<job_id>.steps.run. |
Beta Was this translation helpful? Give feedback.
-
Its a workaround, but a lot of reptition code and not error prone! |
Beta Was this translation helpful? Give feedback.
-
Yes this is not a great solution since you cannot use
with
|
Beta Was this translation helpful? Give feedback.
-
Is there still no way to set a working directory that applies to all the steps in a job? |
Beta Was this translation helpful? Give feedback.
-
@nodesocket I am afraid that I have to say no. What’s your scenario which need to run all steps in a specific path? Let me see whether there’s a work around for you. |
Beta Was this translation helpful? Give feedback.
-
Hey @yanjingzhu , In my case I am using GitHub Actions in a monorepo and I would love to be able the set the working directory on the job level for all steps since I tend to only run a job for a specific sub directory / repo. |
Beta Was this translation helpful? Give feedback.
-
Hi @sharkyze , For job level working-directory , I would recommand you to share your scenario and requirement in the Feedback form for GitHub Actions. Thank you for your understanding. |
Beta Was this translation helpful? Give feedback.
-
@nodesocket Doesn’t this get it done: https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_iddefaultsrun |
Beta Was this translation helpful? Give feedback.
-
@masahigo that worked perfectly. Must have missed that.
|
Beta Was this translation helpful? Give feedback.
-
Take a look at: |
Beta Was this translation helpful? Give feedback.
-
works for me. |
Beta Was this translation helpful? Give feedback.
-
Consider a trivial case. One Repo has multiple projects each in their own sub-folder. The commands require that the project folder be the current folder… Now create workflow/actions so that everything happens for a given project. |
Beta Was this translation helpful? Give feedback.
-
That’s for all jobs, not all tasks in a given job. |
Beta Was this translation helpful? Give feedback.
-
Have you found a way to use
with
? |
Beta Was this translation helpful? Give feedback.
-
You can set working directory as a default for all jobs, default for all steps in a job, or on a per job basis. See the third example here. Does this help you, or did I misunderstand what you are trying to do? |
Beta Was this translation helpful? Give feedback.
-
Workflow syntax for GitHub Actions - GitHub DocsA workflow is a configurable automated process made up of one or more jobs. You must create a YAML file to define your workflow configuration. |
Beta Was this translation helpful? Give feedback.
-
I wish there was a name: wd-inherit
on:
pull_request:
jobs:
defaults:
run:
working-directory: ./proj1
job1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
working-dir: inherit |
Beta Was this translation helpful? Give feedback.
-
I've upvoted things here to try to increase visibility, but I'd like to elaborate our use case just in case that helps the github team. Similarly to others, we have a monorepo To increase org wide stability of CI we want to test those workflows inside the |
Beta Was this translation helpful? Give feedback.
-
Please Response #1 |
Beta Was this translation helpful? Give feedback.
-
Please Response #2 |
Beta Was this translation helpful? Give feedback.
When you use jobs.<job_id>.steps.run , using the working-directory keyword, you can specify the working directory of where to run the command. You need to add work-directory keyword to all jobs.<job_id>.steps.run.
Please refer to this document for more details.
https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun
If you want to use working-directory for entire job, I would suggest to set a job level environment variable, set its value with the directory, and then use context with ${{ env.variablename}} as the value of work-directory keyword in jobs.<job_id>.steps.run.
For Contexts syntax for GitHub Actions …