【问题标题】:Writing a Jenkins Pipeline Shared Library to publish to Nexus NPM repository编写 Jenkins 流水线共享库以发布到 Nexus NPM 存储库
【发布时间】:2018-06-07 22:15:21
【问题描述】:

我曾经使用包含发布阶段的 DSL 管道将我的 NPM 项目发布到 Nexus,其中包含这种步骤:

stage ('Publish') {
  nodejs(nodeJSInstallationName: 'Node LTS', configId: '123456ab-1234-abcd-1234-f123d45e6789') {
    sh 'npm publish'
  }
}

我的 Jenkins 上有一个名为“Node LTS”的 NodeJS 安装和一个带有此 configId 的 npmrc 配置文件。

现在我想将这个阶段导出到一个 groovy SharedLib。 根据Declarative Pipeline documentationthis nodejs-plugin issue,我可以这样写:

    stage('Publish') {
        tools {
            nodejs 'Node LTS'
        }
        steps {
            sh 'npm publish'
        }
    }

但这并没有设置当前在我的 npmrc 配置文件中的身份验证配置:

registry=http://my-nexus/repository/npm-private/
_auth="some=base=64=credential=="
always-auth=true

有没有办法使用声明性语法检索此配置并防止出现此错误消息?

npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

【问题讨论】:

    标签: node.js jenkins jenkins-pipeline jenkins-declarative-pipeline


    【解决方案1】:

    查看 npm 日志文件并阅读文档,我终于发现最好的解决方案是在我的 package.json 文件中指定以下发布配置:

    {
      "name": "@my-company/my-project",
      ...
      "publishConfig": {
        "registry": "http://my-nexus/repository/npm-private/"
      },
      ...
    }
    

    我离开.npmrc 配置:

    registry=http://my-nexus/repository/npm-private/
    _auth="some=base=64=credential=="
    always-auth=true
    

    注意:在我的情况下,自动化脚本需要always-authhttps://docs.npmjs.com/misc/config

    【讨论】:

    • 在 package.json 中添加 publishConfig.registry 选项对我来说并没有真正改变任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2018-02-23
    相关资源
    最近更新 更多