nx
nx copied to clipboard
How to use variables in target scripts with nx run-many command?
I have a script that I added in all my projects' package.json and running nx run-many should update the version number on each file using a pre-defined variable, but currently it's not retrieving the variable's value. I'm on GitHub Actions and here is a piece of my workflow:
updatedVersion = 4.0.0 nx run-many --target=updateProjectsVersion --all
Script in package.json for each project: "updateProjectsVersion": "sed -i /version/s/0.0.0/$updatedVersion/ package.json"
Current Behavior
The value of the variable $updatedVersion is not retrieved, replacing the version number by blank.
Expected Behavior
The sed command should look for the key "version" in each package.json file for the project and replace its value currently set to 0.0.0 by 4.0.0 instead
Steps to Reproduce
If I only run the command directly per projects like nx updateProjectsVersion projectName, it's able to retrieve the value of the variable, but when using nx run-many, it doesn't.
Failure Logs
No failure log
Environment
GitHub Actions running linux
Can you post more of your github actions workflow? There are some details regarding it that could affect this.
My workflow is quite straightforward, if I do an echo $updatedVersion right before the nx run-many command, it does return the value of the variable, so my guess is it seems like it's the nx run-many command that do not translate variables' values within the target script
updatedVersion = 4.0.0
echo $updatedVersion **(returns 4.0.0)**
nx run-many --target=updateProjectsVersion --projects=proj1,proj2
Script in package.json for the both proj1 and proj2:
"updateProjectsVersion": "sed -i /version/s/0.0.0/$updatedVersion/ package.json"
I also tried to use the syntax for an environment variable in the script with env.updatedVersion which also return the correct value when I do an echo, but not within the script.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.