I need to iteratively run an npm command and want to do it from a PowerShell task in a VSTS build step. I cannot use "npm <command>" in PowerShell and have also tried to run commands using "C:\Program Files\nodejs\npm.cmd" "<command>" and Invoke-Expression "C:\Program Files\nodejs\npm.cmd" "<command>" in the PowerShell on the VSTS hosted build agent. How can I run npm commands from a PowerShell build step?
Additionally, the <command> is a custom script from my package.json file. It does not need to be custom. I only put it there to call in a custom npm VSTS build step.
You can call npm command directly through PowerShell task with Hosted agent.
Make sure the Working folder (package.json folder path) of PowerShell task is right.
Regarding custom script in package.json, you need to call it like npm run [script key].
You can call the npm command with the Start-Process and supplying the arguments through -ArgumentList switch seperated by commas
example Start-Process npm -ArgumentList "run","build" -wait
the -wait switch will wait for the task to be completed
Related
We have a PowerShell task ("2.*"), that runs npm install with try catch to enable retry on failure. However npm install fails when run from this task as it can't access the private feed with custom npm packages.
npm ERR! code E401
npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/d2...b7, Basic realm="https://pkgsprodcus1.pkgs.visualstudio.com/", TFS-Federated
The job has the access to OAuth token by scripts enabled but this doesnt seems to work for PS task.
What can we do to make the npm install run in PS task to install w/o E401
I'm afraid the $(System.Accesstoken) here does not available while you npm install targeting to azure devops feed registry.
We provide one task which name is npm Authenticate. Why not directly use this task to authorize before you run npm install in powershell? In another word, put authorization in one separately task, just do npm install in powershell script:
Just configure one .npmrc which at same path level with package.json by adding below script:
registry=https://pkgs.dev.azure.com/{org}/{project name}/_packaging/{feed name}/npm/registry/
always-auth=true
I have a Azure Devops Pipeline $PIPELINE with a task group $TASKGROUP, and one of the actions in that task group is a powershell task $TASK ( a powershell task, not a AzureCloudPowerShellDeployment task or AzurePowershell task, which are different and have answers to this question)
I'd like to run the task under powershell 5.1 because of some features in the script I'm running require it (mainly $PSEdition, which some of the script's module dependencies expect). However, there doesn't seem to be any way to force a specific version of powershell
How can I force the $TASK to run with powershell version 5.1 or higher?
The task simply invokes powershell.exe from the path. It assumes you have installed the appropriate version of PowerShell on the agent.
Your script could relaunch itself to switch between versions..
Or you could enable the PowerShell Core option if your scripts work with that.
There is no PowerShell task in Azure DevOps which will auto-install your desired version of PowerShell.
I created a custom vsts task that merge web.config files and I want to used it in my release pipeline, my task is a powershell and i want to run this powershell on agent machine but it runs in different directory when I give it the source folder it can't find it.
How to change powershell directory to make this task run on agent machine.
Thanks.
By default, the build pipeline will be used the hosted agent, which provided by AzureDevOps.In your case, you need to change this behavior since you need to run your PowerShell script in your machine directory.
For that first, you need to install your self-own agent. Then you can point the directory to your PowerShell script which you'd like to run
Is there a way to add a custom powershell script into the appveyor build script to publish a module to powershellgallery? - The module source would be in the github repo.
If not, maybe it's possible within the appveyor web config itself?
I believe you can create script based Publish-Module command and insert it into right stage of build pipeline. For example if you decide to publish after test stage, it will look like this in YAML:
after_test:
- ps: Publish-Module -Name "MyDscModule" -NuGetApiKey "11e4b435-6cb4-4bf7-8611-5162ed75eb73"
Or in UI you need to go to Settings > Test > Auto > After tests script > PS and enter publish script.
I am trying to automate build process (not Continuous Integration):
Get the code from TFS.
Compile and create build package.
Push the code to a desired shared location.
Should I consider using PowerShell or will msbuild through Command Prompt suffice?
Either will work. We use TFS build definitions to execute MSBuild and MSDeploy.exe commands for our deployments. You can build via the commandline with:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Then use MSDeploy to package the deployment and deploy:
msdeploy.exe -verb:sync -source:dirPath="C:\source\myProject\bin\Release" -dest:package=c:\package.zip
msdeploy.exe -verb:sync -source:package=C:\package.zip -dest:iisApp="Site1/App1" -enableRule:DoNotDeleteRule