vsts-npm-auth can't get authentication token on VSTS build - npm

I'm attempting to use vsts-npm-auth to get the authentication token for our VSTS package repository. On my development machine I can run the commands
npm install -g vsts-npm-auth
vsts-npm-auth -config path-to-my\.npmrc
and it succeeds in providing me with an authentication token. I'm now trying to recreate this as a build step on VSTS, so I create the powershell script auth-vsts.ps1
$npmrcFile = "$PSScriptRoot\path-to-my\.npmrc";
npm install -g vsts-npm-auth;
vsts-npm-auth -config $npmrcFile;
and add it as a powershell task. However, the task fails as follows
2017-05-30T09:37:41.1082686Z ##[section]Starting: auth-vsts
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1092712Z Task : PowerShell
2017-05-30T09:37:41.1092712Z Description : Run a PowerShell script
2017-05-30T09:37:41.1092712Z Version : 1.2.3
2017-05-30T09:37:41.1092712Z Author : Microsoft Corporation
2017-05-30T09:37:41.1092712Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1112679Z ##[command]. 'd:\a\1\s\auth-vsts.ps1'
2017-05-30T09:37:47.3792461Z C:\NPM\Modules\vsts-npm-auth -> C:\NPM\Modules\node_modules\vsts-npm-auth\bin\vsts-npm-auth.exe
2017-05-30T09:37:47.3792461Z C:\NPM\Modules
2017-05-30T09:37:47.3802239Z `-- vsts-npm-auth#0.25.0
2017-05-30T09:37:47.3802239Z
2017-05-30T09:37:47.3802239Z
2017-05-30T09:37:47.3802239Z vsts-npm-auth v0.25.0.0
2017-05-30T09:37:47.3802239Z -----------------------
2017-05-30T09:37:47.3802239Z Creating npmrcFile. Path: D:\a\1\s\.npmrc
2017-05-30T09:37:47.3802239Z Getting new credentials for source:https://our-domain/_packaging/SharedLib/npm/registry/, scope:vso.packaging_write vso.drop_write
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Couldn't get an authentication token for //our-domain/_packaging/SharedLib/npm/registry/:_authToken.
2017-05-30T09:37:50.1769711Z ##[error]Process completed with exit code 1.
2017-05-30T09:37:50.1809715Z ##[section]Finishing: auth-vsts
The error gives no indication as to why it can't obtain the credentials. Any ideas why this might be?

I faced this issue while trying to execute via Visual Studio Code`s powershell terminal
vsts-npm-auth -config .npmrc
But running the same command via simple console solved this issue and I was redirected to authentication window.
Can suggest that due to internal limitations powershell disabled to open another windows.

The error did indicate why it cannot obtain the credentials:
The prompt option is invalid because the process is not interactive.
This could be caused by the build agent does not run in interactive mode which make the credential dialog cannot be prompted. If you are using Hosted Build Agent, the build agent is run as service and there isn't any way to change to interactive mode.
However, the issue here is that if you want to use the feed in a build step, it does not make sense to prompt a credential dialog during the build process since the build step cannot enter the required credential automatically. Not sure if there is any specific requirement in your environment, but the general workflow should be uploading the .npmrc file generated in your local machine to the Source Control so that npm can use the auth token in the file to install/publish packages to VSTS Feed.

Inside your project, you can open a terminal and run
vsts-npm-auth -F -C .npmrc
This script refreshes the npm token. Here I set two parameters: -F forces the refresh (if not set, the token is refreshed only if it is already expired), while -C fileName defines the configuration file.

The vsts authentication system sometimes authenticates the use by popping up a browser window. If the terminal you're running the command from is not interactive (e.g., ssh terminal, vscode terminal) it won't be able to pop up that window, and the authentication will fail.

This worked for me
npx vsts-npm-auth -config .npmrc

Related

azure devop selfhosted agent, newman command not recognized

Trying to run my postman collection in azure devops inside a self-hosted agent. When I try to run the command inside the agent "newman run postman_collection.json -e postman_environment.json -r cli,htmlextra" it's running fine. But when I run the same through a a command line script task in release pipeline it's throwing the error "newman is not recognized..". I also tried to have a npm task for newman installation i.e. "npm install -g newman" it's also throwing the erro "##[error]Unable to locate executable file: 'newman'. Please verify either the file path exists or the file can be found within a d...."
azure devop selfhosted agent, newman command not recognized
According to the error message "##[error]Unable to locate executable file: 'newman" when you using the npm install -g newman, you could try to add C:\Users\[BUILDSERVER-USERNAME]\AppData\Roaming\npm to the PATH variable for the [BUILDSERVER-USERNAME] user.
You could refer to this document How to fix the Newman task for Team Foundation Server silently failing for some more details.
Besides, when we use command line to install the newman, it will take a few minutes to install it, so we need to wait for a few minutes before we using the command line:
"newman run postman_collection.json -e postman_environment.json -r cli,htmlextra"
You could add powershell task to sleep a few minutes:
echo "Sleeping for 10 mins..."
Start-Sleep -s 600

"Directory name is invalid." etc. with rabbitmq-plugins on Windows

I'm trying to get RabbitMQ going on Windows 10 by following these instructions.
However, when trying to enable the management plugin via powershell command:
./rabbitmq-plugins enable rabbitmq_management
I get the following:
The directory name is invalid.
The filename, directory name, or volume label syntax is incorrect.
Unsupported node name: hostname is invalid (possibly contains unsupported characters).
If using FQDN node names, use the -l / --longnames argument.
I've tried setting HOMEDRIVE=C: as the blog suggested.
What am I doing wrong?
EDIT
Per the comment below I did the following:
PS C:\program files\rabbitmq server\rabbitmq_server-3.7.15\sbin> ./rabbitmq-service.bat stop
The directory name is invalid.
The filename, directory name, or volume label syntax is incorrect.
The RabbitMQ service is stopping.
The RabbitMQ service was stopped successfully.
PS C:\program files\rabbitmq server\rabbitmq_server-3.7.15\sbin> ./rabbitmq-service.bat uninstall
The directory name is invalid.
The filename, directory name, or volume label syntax is incorrect.
*********************
Service control usage
*********************
rabbitmq-service help - Display this help
rabbitmq-service install - Install the RabbitMQ service
rabbitmq-service remove - Remove the RabbitMQ service
The following actions can also be accomplished by using
Windows Services Management Console (services.msc):
rabbitmq-service start - Start the RabbitMQ service
rabbitmq-service stop - Stop the RabbitMQ service
rabbitmq-service disable - Disable the RabbitMQ service
rabbitmq-service enable - Enable the RabbitMQ service
PS C:\program files\rabbitmq server\rabbitmq_server-3.7.15\sbin> set HOMEDRIVE=C:
PS C:\program files\rabbitmq server\rabbitmq_server-3.7.15\sbin> ./rabbitmq-service.bat install
The directory name is invalid.
The filename, directory name, or volume label syntax is incorrect.
RabbitMQ service is already present - only updating service parameters
"WARNING: Using RABBITMQ_ADVANCED_CONFIG_FILE: C:\Users\Mj\AppData\Roaming\RabbitMQ\advanced.config"
2019-06-14 10:55:09.630000
args: []
format: "Failed to create cookie file 'l:/.erlang.cookie': enoent"
label: {error_logger,error_msg}
2019-06-14 10:55:09.630000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{auth,init,['Argument__1']}},{pid,<0.57.0>},{registered_name,[]},{error_info,{error,"Failed to create cookie file 'l:/.erlang.cookie': enoent",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[net_sup,kernel_sup,<0.46.0>]},{message_queue_len,0},{messages,[]},{links,[<0.55.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,1456}],[]]}
2019-06-14 10:55:09.635000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{"Failed to create cookie file 'l:/.erlang.cookie': enoent",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{offender,[{pid,undefined},{id,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
2019-06-14 10:55:09.704000 supervisor_report #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{shutdown,{failed_to_start_child,auth,{"Failed to create cookie file 'l:/.erlang.cookie': enoent",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}},{offender,[{pid,undefined},{id,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
2019-06-14 10:55:09.742000 crash_report #{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.45.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Failed to create cookie file 'l:/.erlang.cookie': enoent",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,"application_master.erl"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[<0.44.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.46.0>,normal}]},{links,[<0.44.0>,<0.43.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,987},{stack_size,27},{reductions,184}],[]]}
2019-06-14 10:55:09.789000 std_info #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Failed to create cookie file 'l:/.erlang.cookie': enoent",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Failed to create cookie file 'l:/.erlang.cookie': enoent\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Failed to create cookie file 'l:/.er
Crash dump is being written to: C:\Users\Mj\AppData\Roaming\RabbitMQ\log\erl_crash.dump...done
Seems that the Order at which the commands are ran Matters, this worked for me, shuffle them around
SET HOMEDRIVE=C:
rabbitmq-plugins.bat enable rabbitmq_management
rabbitmq-service.bat stop
rabbitmq-service.bat install
rabbitmq-service.bat start
Based off of the comment #LukeBakken made in the original question, I was able to get around this by creating a local admin user and doing the install under the local admin user. This was after hours of battling by setting the HOMEDRIVE, etc.
I solved this by following way :
1. Opened command prompt using administrative mode
2. Go to sbin directory. Execute command "SET HOMEDRIVE=C:"
Based on the comment from Luke Bakken, this is what worked for me:
Almost the same as his comment, but instead of uninstall I had to use remove. uninstall was not recognized.
"Log in as the admin user you installed RMQ with; Open the "RabbitMQ Command Prompt (sbin dir)" terminal, run:"
.\rabbitmq-service.bat stop
.\rabbitmq-service.bat remove
set HOMEDRIVE=C:
.\rabbitmq-service.bat install
.\rabbitmq-plugins.bat enable rabbitmq_management
.\rabbitmq-service.bat start

Gitlab-CI cannot clone

I have a very basic integration configured for Gitlab-CI but it fails almost at the beginning when it has to clone the code.
My integration is this:
image: node:latest
stages:
- build
- test
cache:
paths:
- node_modules/
- dist/
build-prod:
stage: build
script:
- npm install
- npm run build-prod
artifacts:
paths:
- node_modules/
- dist/
test_with_karma:
stage: test
script: ng test
And the error that I get is this:
Running with gitlab-runner 11.7.0 (8bb608ff)
on fakehost 2eaf11ea
Using Docker executor with image node:latest ...
Pulling docker image node:latest ...
Using docker image sha256:8c67bfd7b95bdc535edc4a4144f5392b0f73efd6385fbcb47747d028d7059359 for node:latest ...
Running on runner-2eaf11ea-project-56-concurrent-0 via fakehost...
Cloning repository...
Cloning into '/builds/redacted/frontend'...
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx#working-domain.com/redacted/frontend.git/': The requested URL returned error: 403
/bin/bash: line 65: cd: /builds/redacted/frontend: No such file or directory
ERROR: Job failed: exit code 1
What is the problem here?
Check if this is covered by gitlab-org/gitlab-ce issue 39469
YAY - it works for me. This problem seems to have multiple solutions.
The one that worked for me is #44855
To summarize. Being an Administrator on Gitlab does not mean you have the "access" to do whatever you want to do in Gitlab.
"Unable to access" permissions applies to the person who is logged into Gitlab and running the job.
To fix the problem - the person / account running the job must be a member (master) of the project.
This will apply to private projects.
It is not necessary to make a private project Public even though that appears to fix the problem. GITLAB suggests you must have https for the project to work you can use http.
SOLUTION - add your account to the project even if you are the Administrator
And:
Conrad has described it correctly.
You need to have rights to the project to run pipeline, however, as administrator, you can start any pipeline.
I've got the case when the user being Admin in Gitlab could push his commit from command line, although theoretically having no rights to project - and the pipeline has failed.
This inconsistency need to be fixed, either Admin user should not be able to push/start pipeline, having no rights for it, or he should authomatically be granted all rights to all projects. I'd prefer the first one, because it separates gitlab administration from project rights. Sometimes I prefer not having full rights, just like working as non-root under Linux.

TeamCity ssh user

I'm trying to run a script from Teamcity Agent on other environment (mac).
I am using script that contains 'ssh administrator#33.333.33.33..'
when running the script as administrator on the Teamcity agent environment it works (after I used the publicKey). when running the Teamcity project I'm getting
[Step 1/1] Permission denied (publickey,keyboard-interactive).
[00:18:15][Step 1/1] Process exited with code 255
[00:18:15][Step 1/1] Step run protractor test (Command Line) failed
I've tried also adding the ssh key file to the project as seen here
https://confluence.jetbrains.com/display/TCD8/SSH+Keys+Management
I'm still getting the error. I assume that maybe Teamcity Agent uses other user (than Administrator) to run the script.
any ideas?
This may be of use, but is potentially not a "TeamCity" issue
Permission denied (publickey,keyboard-interactive)
Script is run using the account which is running Teamcity agent service. You need to make sure this account has enough rights to run the script.

Jenkins workspace error on ssh&Mercurial plugin

I met this problem when I was trying to config Jenkins to fetch the repository on the server of a fellow(university course).
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/TEST1/workspace
$ hg clone --rev default --noupdate ssh://XXX#partch.anu.edu.au/XXX/XXX /var/lib/jenkins/jobs/TEST1/workspace
remote: Host key verification failed.
abort: no suitable response from remote hg!
ERROR: Failed to clone ssh://XXX#partch.anu.edu.au/XXX/XXX
ERROR: Failed to clone ssh://XXX#partch.anu.edu.au/XXX/XXX
Finished: FAILURE
Then I tried to do the same command in terminal, with the different error
abort: Permission denied: /var/lib/jenkins/jobs/TEST1/workspace
I tried to change the location for the command:
hg clone --rev default --noupdate ssh://XXX#partch.anu.edu.au/XXX/XXX /home/administrator/TEST
And it works
According to all these, and the fact that this is no workspace(Error: no workspace)--I know it's because of no successful build ever.
Is it a problem with the workspace configuration of Jenkins? but don't know what to do.
Thank you very much if anyone gives me some advice!
Your error doesn't mention anything about a workspace. There error clearly states that it comes from remote hg and it is an authentication failure.
Also, are you using the Mercurial Plugin to perform the SCM checkout or trying to replicate it with a Build Shell build step?