PowerShell task for Azure pipeline fails to load private npm packages - powershell

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

Related

How to run python playwright in Azure functions

Playwright worksf on my machine when I run it through the normal Python interpreter, but when I try to deploy it as an Azure function I get errors.
I'm trying to follow instructions here but I'm getting "webkit" browser was not found. Please complete Playwright installation via running "python -m playwright install" which I think is an error that can't occur if you're using npm.
I've tried creating an azure devops Pipeline which has this step:
- bash: |
python -m venv worker_venv
source worker_venv/bin/activate
pip install -r requirements.txt
python -m playwright install
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
I've also tried just doing it from my code:
os.system('python -m playwright install')
I can see that the PLAYWRIGHT_BROWSERS_PATH environment variable is set to 0.
How can I get this to run on Azure functions?
As you mentioned the code works locally and it doesn't work when you deploy it to azure function. It seems you haven't add the modules which you installed into requirements.txt. When you deploy it to azure function, azure cloud will install the modules according to requirement.txt. So just add a line like playwright==0.162.1 in your requirements.txt.

Installing public npm packages from the GitHub package registry

1.I publish a public package in an organization repo.
The repo link : https://github.com/JX3BOX/jx3box-config/packages/141887
2.And I wanna install the package from another repo.
I had set the dependencies in the package.json
"dependencies": {
"#jx3box/jx3box-config": "^1.0.3",
and I created a file named .npmrc ,and set :
#jx3box:registry=https://npm.pkg.github.com
3.When I use github actions to build
There is an error occur
Running build scripts... npm install && npm run build
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"
It means maybe I need auth.But This is an public package.Is it should be auth too?
4.Now I had to prepend a line in the file .npmrc,just like
//npm.pkg.github.com/:_authToken=<mytoken>
But how can I set it in the actions .
or because this is a public pkg,how can I don't need any auth?
Thanks a lot!! ^_^
This is probably solved but posting anyway because this question ranks high on Google.
From the GitHub Docs:
You need an access token to publish, install, and delete packages. You can use a personal access token to authenticate with your username directly to GitHub Packages or the GitHub API.[...]
You cannot install packages (even public ones) from the GitHub npm registry without being authenticated.
More details and multiple authentication methods here:
https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages
The docs should be updated.
You need an access token to publish, install, and delete packages.
This should really be changed to;
You need an access token to publish, install, and delete both private and public packages.

Configure npm to resolve dependencies using JFrog Artifactory as proxy for both npm registry and GitHub

I have a build server with no internet access, and I need to resolve dependencies from both github.com and registry.npmjs.org. The build server has access to Artifactory(jfrog), so I have created an npm repo to proxy for registry.npmjs.org and that is working, and I just created dependency-rewrite mechanism under virtual repo for remote npm repo as mentioned in this link--Configure npm to resolve dependencies using artifactory as proxy for both npm registry and github
after configuring still I face the same issue:
node-sass#4.11.0 install /app/jenkins/workspace/uiwidget_smarthome1.0_dev/bwtk/node_modules/node-sass
node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-47_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-47_binding.node":
How can I configure npm to resolve from both of these? Since the 2 repos are different types, I can't aggregate them into a single virtual repo. Can npm be configured to resolve dependencies from both of these?
Yes, you need to pass the virtual repo url to the npm command. You can use ---registry virtual repo url or you can set the registry to using npm command

Run custom npm command in Powershell on VSTS hosted build agent

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

Automated API tests with Postman, Newman on IBM Bluemix/DevOps

I would like to add a test stage in the IBM Bluemix DevOps "Build Deploy" function to test APIs using Postman and Newman but I don't see how to do that. Any advice on where to look?
In the Build and Deploy pipeline, if you select the Add Stage you can add a new Test job to be ran after each update to the source code repository.
When configuring the stage, you can add a "Test" job with the "Simple" tester type. This lets you give shell commands to be executed in the project directory.
Using Newman can be achieved using NPM to manage the package. Providing you have the newman package listed in your project dependencies, you could set up an NPM script command to run the tests as below.
"scripts": {
"test": "newman -c tests.json"
},
This would allow you to run the following test stage to execute your tests.
#!/bin/bash
# invoke tests here
npm install
npm test