Can not execute subscript in bitbucket-pipeline.yaml with npm to inject version number to helm environment variable

9/16/2019

I want to add the version number of my package.json as a env variable to my bitbucket pipeline.

Executing it locally works fine:

[xetra11@x11-work app-frontend]$ PKG_VER="$(node -p "require('./package.json').version")"
[xetra11@x11-work app-frontend]$ echo $PKG_VER
0.2.1-rc.1

In the bitbucket pipeline step I want to do the same for the version environment variable

  - step: &deploy
      name: Deploy Dev
      caches:
        - node
      deployment: dev
      trigger: automatic
      image:
        name: eu.gcr.io/my-cluster/cloud-sdk-helm:1.0.0
        username: _json_key
        password: $GCLOUD_API_KEYFILE
      script:
        # authenticate with gcloud
        - echo $GCLOUD_API_KEYFILE > ~/.gcloud-api-key.json
        - gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json
        - gcloud config set project $GCLOUD_PROJECT
        - gcloud container clusters get-credentials $GCLOUD_CLUSTER --zone=$GCLOUD_ZONE --project $GCLOUD_PROJECT
        - gcloud auth configure-docker --quiet
        # deploy to kubernetes
        - helm upgrade --install app-frontend-$DEPLOYMENT_ENV --namespace=$DEPLOYMENT_ENV >-
          --set env=$DEPLOYMENT_ENV >-
          --set image="eu.gcr.io/my-cluster/app-frontend:$BITBUCKET_COMMIT" >-
          --set version="$(node -p "require('./package.json').version")" >-
          ./helm

At the bottom you can see I am doing this

--set version="$(node -p "require('./package.json').version")" 

The result of this attempt is the following error message. My pipeline builds but the version is not applied

+ helm upgrade --install app-frontend-$DEPLOYMENT_ENV --namespace=$DEPLOYMENT_ENV >- --set env=$DEPLOYMENT_ENV >- --set image="eu.gcr.io/my-cluster/app-frontend:$BITBUCKET_COMMIT" >- --set version="$(node -p "require('./package.json').version")" >- ./helm
bash: node: command not found

I do not understand. As cache I use node and therefore should be able to execute node.

-- xetra11
bash
bitbucket
kubernetes-helm
node.js
npm

0 Answers