美文网首页
利用gitlab CI做到npm 包push 后直接发布,自动

利用gitlab CI做到npm 包push 后直接发布,自动

作者: 凤梨罐头过期了 | 来源:发表于2020-04-08 10:46 被阅读0次

    自动发布的难点在于用命令自动登陆npm,正常发布要npm login,然后手动输入用户名密码,但是自动发布不能这样做。

    • 编写.npmrc文件
    registry=http://yourbindingRegistryServerHost
    //yourbindingHost:always-auth=false
    //yourbindingRegistryServiceHost:_password=加密过的密码串
    //yourbindingRegistryServiceHost:username=myname
    //yourbindingRegistryServiceHost:email=myname@localhost.com
    //yourbindingRegistryServiceHost:_authToken="xxxxx"
    
    • 编写CI文件,
    // .gitlab-ci.yml
    before_script:
     - node -v
     - yarn -v 
     - yarn config set proxy http://xxxxx:xxx
     - yarn 
    
    stages:
     - merge 
     - publish
    
    job1:
     stage: mege
      script:
        - git pull origin master:develop
        ......
    
    job2:
     stage: mege
      script:
        - npm  version patch
        - git commit -am 'chore:build'
        - git publish --userconfig=./.npmrc
        - git push xxxxxxx --tags
    

    之前有另一个例子是这样的,我是参考他的,但是一直无法成功,原因是他的nomrc文件缺少token,一直校验不通过
    https://segmentfault.com/a/1190000015692830

    token可以通过 cat ~/.nomrc获取
    那些私密变量在ci里面设置secret variable

    相关文章

      网友评论

          本文标题:利用gitlab CI做到npm 包push 后直接发布,自动

          本文链接:https://www.haomeiwen.com/subject/oijzphtx.html