簡體   English   中英

如何在 GitLab CI 中添加私有節點模塊

[英]How to add private node module in GitLab CI

我能夠將我的私人倉庫(在 GitLab 中)用作我正在開發的應用程序的本地節點模塊。 I did this by generating a personal access token in GitLab and then running this command locally with the PAT as an environment variable: git config --global url."https://oauth2:${GITLAB_PERSONAL_ACCESS_TOKEN}@gitlab.com/".insteadOf https://gitlab.com/

但是,當我嘗試使用 GitLab CI 部署我的應用程序時,我的工作失敗並出現錯誤:

HTTP 基本:訪問被拒絕...“https://gitlab.com/myuser/myrepo.git/”的身份驗證失敗

我確保 PAT 在 GitLab CI 環境變量中並且可以訪問。 它也用於我的測試作業(構建、lint、jest),我可以確認它正在被使用,因為當我將它從這些作業中取出時,它們也會因同樣的錯誤而失敗。 所以它適用於他們,但不適用於部署。 在此處輸入圖像描述

package.json

...
"dependencies": {
  "my-dependency": "git+https://gitlab.com/myuser/myrepo.git",
...

.gitlab-ci.yml (lint、jest、build 都失敗並出現同樣的錯誤)

image: node:14.17.1

.git_config: &git_config |
  git config --global url."https://oauth2:${GITLAB_PERSONAL_ACCESS_TOKEN}@gitlab.com/".insteadOf https://gitlab.com/

.npm_install: &npm_install |
  npm ci --cache .npm --prefer-offline --ignore-scripts --include=dev

stages:
  - test
  - deploy

# Cache modules in between jobs
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm/

lint:
  stage: test
  before_script:
    - *git_config
    - *npm_install
  script:
    - npm run lint

jest:
  stage: test
  before_script:
    - *git_config
    - *npm_install
  script:
    - npm test

build:
  stage: test
  script:
    - *git_config
    - NODE_ENV=production npm ci # this is what Heroku will run

deploy-prod:
  stage: deploy
  image: ruby:latest
  before_script:
    - *git_config
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
  script:
    - dpl --provider=heroku --app=$HEROKU_APP_PROD --api-key=$HEROKU_API_KEY
  only:
    - master
    - production
  environment:
    name: production
    url: https://app.myapp.com
  when: manual

在您的package.json包含您的依賴項,如下所示:

"package-name": "git+https://USER:PAT_TOKEN@gitlab.com/USER/package-name"

替換package-nameUSERPAT_TOKEN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM