Get value of package.json in gitLab CI YML

后端 未结 6 2155
小鲜肉
小鲜肉 2021-02-13 03:25

I\'m using gitLab CI for my nodejs application. In my YML file I need to call a script to build a docker image. But instead of using latest I need to use the curren

6条回答
  •  星月不相逢
    2021-02-13 03:43

    I would argue the easiest way to retrieve version from your package.json is to use node itself.

    build:
      stage: build
      script:
        - export VERSION=$(node -p "require('./package.json').version")
        - export CONTAINER_RELEASE_IMAGE=$CI_REGISTRY_IMAGE:$VERSION
        - cd /opt/core/bundle && docker build -t $CONTAINER_RELEASE_IMAGE .
        - docker push $CONTAINER_RELEASE_IMAGE
    

提交回复
热议问题