如何在JFrog CLI中将npm-install与--build-name和--build-number命令选项一起用作非管理员用户?

时间:2018-06-06 08:19:18

标签: npm artifactory jfrog-cli

描述

我正在尝试设置JFrog的Artifactory Pro(v 6.0.1)来存储和缓存项目的依赖项。我想使用JFrog CLI来收集和发布npm-build信息给Artifactory,就像在这个(https://jfrog.com/blog/npm-flies-with-jfrog-cli/)博客文章中描述的那样,但我希望能够以 -admin用户。

设置

Artifactory包含一个名为 npm 的虚拟存储库,它是本地(名为 npm-local )和远程(名为 npm-remote <的集合) / em>)repository。

有两个用户:名为 admin 的用户具有管理员权限,用户名为开发人员且没有管理员权限。

配置JFrog CLI:

# create a configuration for the admin
jfrog rt config --user=admin \
    --password=admin \
    --url=http://localhost:8081/artifactory \
    --interactive=false rt_admin

# create a configuration for the developer
jfrog rt config --user=developer \
    --password=developer \
    --url=http://localhost:8081/artifactory \
    --interactive=false rt_dev

我正在做什么

对于此测试,我尝试构建simple-node-js-react-npm-app(https://github.com/jenkins-docs/simple-node-js-react-npm-app)并使用以下JFrog CLI命令将其发布到Artifactory中的本地npm存储库:

jfrog rt npm-install npm \
    --build-name=simple \
    --build-number=1.0.0 \
    --server-id=rt_dev

这会在命令完成之前产生以下错误(如果忽略npm-install阶段的错误):

[Info] Collecting dependencies information, this might take several minuets...
[Error] Artifactory response: 400 Bad Request
For permissions reasons AQL demands the following fields: repo, path and name.

当我继续

jfrog rt npm-publish npm \
    --build-name=simple \
    --build-number=1.0.0 \
    --server-id=rt_dev
jfrog rt build-publish simple 1.0.0 --server-id=rt_dev

新发布的工件没有依赖关系。

如果以与管理员相同的方式发布

jfrog rt npm-install npm \
    --build-name=simple \
    --build-number=1.0.1  \
    --server-id=rt_admin
jfrog rt npm-publish npm \
    --build-name=simple \
    --build-number=1.0.1 \
    --server-id=rt_admin
jfrog rt build-publish simple 1.0.1 --server-id=rt_admin

我获得了超过1000个依赖项。

如何获得与非管理员用户相同的结果?

1 个答案:

答案 0 :(得分:0)

如果这有帮助,我试图重现这种行为,但无法做到。已使用CLI成功构建并使用非管理员用户发布(请参阅下面的构建日志)。

在您的情况下,您可以通过在DEBUG上运行JFrog CLI来调试它。

$ echo "$ARTIFACTORY_URL"
https://arielk.jfrog.io/arielk
$ echo "$ARTIFACTORY_USER"
npm
$ echo "$ARTIFACTORY_NPM_REPOSITORY"
npm
$ chmod 777 jfrog
$ ./jfrog rt config --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --password=$ARTIFACTORY_PASS
Artifactory server ID: [Info] Encrypting password...
$ ./jfrog rt c show
Server ID: Default-Server
Url: https://arielk.jfrog.io/arielk/
User: npm
Password: ***
Default:  true

$ ./jfrog rt npmi $ARTIFACTORY_NPM_REPOSITORY --build-name=gitlabci-npm-artifactory --build-number=$CI_JOB_ID
[Info] Running npm Install.
npm notice created a lockfile as package-lock.json. You should commit this file.
{
  "added": [
    {
      "action": "add",
      "name": "inherits",
      "version": "2.0.1",
      "path": "/builds/ArielKJFrog/NPM-TEST/node_modules/inherits"
    },
    {
      "action": "add",
      "name": "util",
      "version": "0.10.3",
      "path": "/builds/ArielKJFrog/NPM-TEST/node_modules/util"
    },
    {
      "action": "add",
      "name": "assert",
      "version": "1.4.1",
      "path": "/builds/ArielKJFrog/NPM-TEST/node_modules/assert"
    },
    {
      "action": "add",
      "name": "colors",
      "version": "1.3.0",
      "path": "/builds/ArielKJFrog/NPM-TEST/node_modules/colors"
    }
  ],
  "removed": [],
  "updated": [],
  "moved": [],
  "failed": [],
  "warnings": [],
  "elapsed": 3734
}
[Info] Collecting dependencies information, this might take several minuets...
[Info] npm install finished successfully.
$ ./jfrog rt bce gitlabci-npm-artifactory $CI_JOB_ID
[Info] Collecting environment variables...
[Info] Collected environment variables for gitlabci-npm-artifactory/72931109.
$ ./jfrog rt npmp $ARTIFACTORY_NPM_REPOSITORY --build-name=gitlabci-npm-artifactory --build-number=$CI_JOB_ID
[Info] Running npm Publish
npm notice 
npm notice package: gitlabci-npm-artifactory@1.0.0
npm notice === Tarball Contents === 
npm notice 693B    package.json        
npm notice 1.3kB   .gitlab-ci.yml      
npm notice 129B    index.js            
npm notice 20.2MB  jfrog               
npm notice 947B    README.md           
npm notice 497.7kB img/Screen_Shot1.png
npm notice 379.3kB img/Screen_Shot2.png
npm notice 420.0kB img/Screen_Shot3.png
npm notice 490B    test/test.js        
npm notice === Tarball Details === 
npm notice name:          gitlabci-npm-artifactory                
npm notice version:       1.0.0                                   
npm notice filename:      gitlabci-npm-artifactory-1.0.0.tgz      
npm notice package size:  6.8 MB                                  
npm notice unpacked size: 21.5 MB                                 
npm notice shasum:        81be9defef61f0afaa9e9503c17b611f59c90bdb
npm notice integrity:     sha512-bbLIHqj3THLma[...]+UNMCLsnVSQsA==
npm notice total files:   9                                       
npm notice 
gitlabci-npm-artifactory-1.0.0.tgz
[Info] [Thread 2] Uploading artifact: /builds/ArielKJFrog/NPM-TEST/gitlabci-npm-artifactory-1.0.0.tgz
[Info] npm publish finished successfully.
$ ./jfrog rt bag gitlabci-npm-artifactory $CI_JOB_ID
[Info] Collecting git revision and remote url...
[Info] Collected git revision and remote url for gitlabci-npm-artifactory/72931109.
$ ./jfrog rt bp gitlabci-npm-artifactory $CI_JOB_ID
[Info] Deploying build info...
[Info] Build info successfully deployed. Browse it in Artifactory under https://arielk.jfrog.io/arielk/webapp/builds/gitlabci-npm-artifactory/72931109