Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how can I access the package.json version while running pipeline

Yassine Jouahri March 20, 2018

I have setup a test pipeline and deployment pipeline.

During deployment I'd like to get package.json version and put the value in a new variable.

I have found some ways that work in bash like:

first creation a version script in package.json that return the version:

"version": "echo $npm_package_version"

Then assigning the result to a variable.

$VERSION=$(npm run version --silent)

 Is there a way to do this in the pipeline?

When trying I get an error :

+ $VERSION=$(npm run version --silent)bash: =1.0.6: command not found

It retrieves the version number but still throws an error ?

any suggestions are welcome

2 answers

1 accepted

5 votes
Answer accepted
davina
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2018

Hi Yassine,

 

You can create a version script as you mentioned in your package.json

"scripts": {
"version": "echo $npm_package_version"
}

and then you can add to your bitbucket-pipelines.yml

VERSION=$(npm run version --silent)

The example you provided does not work because of the $ in front of VERSION.

 

Hope this helps!

Yassine Jouahri March 27, 2018

@davina Thank you for your answer. I had indeed made a syntax mistake there.

The solution now works perfectly.

0 votes
Olalekan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 17, 2024 edited

Can someone help, please. The "npm run" is not working in my pipeline. Here is the line of code:

default:
- step:
name: get the VERSION number
script:
- echo "Running npm version command"
- VERSION=$(npm run npm-version --silent)
- echo "Version retrieved from npm = $VERSION"
I have this in package.json :
"npm-version": "echo $npm_package_version",

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery learning path, product discovery training, idea prioritization, align stakeholders, discovery to delivery, product collaboration, atlassian learning, dev process, roadmap planning, insight capture, team alignment

Elevate Your Skills with Jira Product Discovery!

Unlock your potential and learn how to use Jira Product Discovery to your advantage. You’ll have the expertise to revolutionize ideas and insights, roadmapping, engage and align teams and stakeholders, and deliver the best solutions—faster. Enroll today!

Start Learning
AUG Leaders

Atlassian Community Events