Home > OS >  Gitlab-ci private package install fails
Gitlab-ci private package install fails

Time:10-11

I'm using the gitlab-ci (13.9) to test and build a react project.

On the branch develop everything works fine.

On the branch validation, the build job can't install a private package:

[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@company/name-of-my-package: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/builds/code/conference/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Command failed with exit code 1.

The .gitlab-ci.yml is the same for both branches:

variables:
    DOCKER_DRIVER: overlay2
    GIT_SSL_NO_VERIFY: 'true'
    DOCKER_TLS_CERTDIR: ''

stages:
    - install
    - test
    - build

install_dependencies:
    image: node:lts-alpine
    stage: install
    before_script:
        - apk update && apk add git openssh-client
        - eval $(ssh-agent -s)
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
        - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
        - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc

    artifacts:
        expire_in: 1 hour
        paths:
            - node_modules/
    script:
        - yarn install

test-job:
    image: node:lts-alpine
    stage: test
    script:
        - yarn run test

build-job:
    image: node:lts-alpine
    stage: build
    only:
        - develop
        - validation
    artifacts:
        expire_in: 1 hour
        paths:
            - dist/
    script:
        - yarn run build

  • The package.json is the same for both branches.
  • Both branches are protected.
  • develop is the project default branch.
  • There is no error log available /builds/code/conference/yarn-error.log
  • There is no specific variable config in .gitlab-ci for develop

What could cause this to fail ?

CodePudding user response:

I managed to make my CI pass on the branch validation by copying the ssh/npmrc configuration in my build-job:

variables:
    DOCKER_DRIVER: overlay2
    GIT_SSL_NO_VERIFY: 'true'
    DOCKER_TLS_CERTDIR: ''

stages:
    - install
    - test
    - build
    - docker-build-push

install_dependencies:
    image: node:lts-alpine
    stage: install
    before_script:
        - apk update && apk add git openssh-client
        # run ssh agent
        - eval $(ssh-agent -s)
        # add ssh key stored in gitlab ci variables
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
        - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
        - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
    artifacts:
        expire_in: 1 hour
        paths:
            - node_modules/
            - .npmrc
    script:
        - yarn install

test-job:
    image: node:lts-alpine
    stage: test
    script:
        - yarn run test

build-job:
    image: node:lts-alpine
    stage: build
    only:
        - develop
        - validation
    artifacts:
        expire_in: 1 hour
        paths:
            - dist/
    before_script:
        - apk update && apk add git openssh-client
        # run ssh agent
        - eval $(ssh-agent -s)
        # add ssh key stored in gitlab ci variables
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
        - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
        - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
    script:
        - yarn run build

docker-job:
    services:
        - docker:dind
    image: docker:18.09.9
    stage: docker-build-push
    only:
        - develop
        - validation
    before_script:
        - apk update && apk add git rsync curl jq
        - docker login -u gitlab-ci-token -p ${PUBLISH_KEY} registry.apizee.com
    script:
        - docker login -u gitlab-ci-token -p ${PUBLISH_KEY} registry.apizee.com
        - /bin/sh docker/init.sh
        - docker push registry.apizee.com/docker/apizee-rancher/conf4:${CI_COMMIT_REF_NAME}
        - '[[ -f "docker/deploy.sh" ]] && sh docker/deploy.sh "${CI_COMMIT_REF_NAME}"'

So there might be a default cache/artifacts setting on the default branch and not on other branches ?

  • Related