I have a Bamboo server that is currently setup to test my builds on my project.
I want to start versioning my project using NPM version or grunt bump.
Here is the current Bamboo setup I have,
Bamboo detects repo change
Runs all the test
If the branch is the 'master' branch, then do a post job of moving our production code into an artifactory (we just zip up the appropriate files and drop them into it).
I would like to be able to increment the version between step 2 and 3 if the branch is 'master'.
I'm trying to come up with a good solution for this.
I'm wondering if something like just doing npm version or npm bump is enough? It seems that I would want to them commit that back to the git repo?
Looking for some possible suggestions
First detect that you're on the master branch. If so, do an npm version update. You also need to tell git to push to the remote repository rather than to the repo cached on the Bamboo server. For example, in a script task on your build plan:
npm install
npm run build
if [[ "${bamboo.planRepository.branchName}" == "master" ]]; then
# configure git to use the remote repo
git remote set-url origin ${bamboo.planRepository.1.repositoryUrl}
rm .git/objects/info/alternates
git fetch
# update the local version
# this will increment the last version number, commit and tag the commit
npm version patch
# create your artifact
npm pack
# push the version update
git push
git push --tags
fi
Related
Background
I have a project that's split into several smaller projects with one main project that downloads the others as dependencies of the main project.
I'm using Gitlab to host my projects in private repositories, using deploy tokens to allow npm install to download them.
The dependencies are added to the main project using the following format in package.json:
git+https://name:token#gitlab.com/group/project.git
Problem
On Windows when I do a git clone of my main project and run npm install, it does download all the assets using Git LFS, but on Ubuntu the assets aren't getting downloaded. If I check the contents of all the files tracked by Git LFS all I get is the information Git LFS placeholder. I'm using identical commands and software versions on Windows and Ubuntu, but with different results.
I've tried:
Updating to same versions of Node(10.16.0) and Npm(6.10.2) on both Windows and Ubuntu
Updating to the latest versions of Node and Npm (I had to stick to version 10.x for Node because of some dependencies not working with 12.x)
Adding a .lfsconfig file that points to the repository as described in the following issue: https://github.com/npm/npm/issues/11151
Updating Git to the latest version (2.21 on Windows and 2.22 on Ubuntu)
Current workaround
Currently I'm cloning the main project then manually cloning my dependencies into node_modules so that they're all proper git repositories so that I can then use git lfs pull in them. It works, but it's not how it should work, especially not since it's working as it should on Windows.
Question
Why is npm install handling Git LFS differently for dependencies on Ubuntu vs Windows? How do I get npm install to work properly with Git LFS on dependencies, is there a settings somewhere I need to change to e.g. enforce Git LFS downloading?
Step 1. Inside of your repository, run the following command and then commit the resulting .gitconfig and push:
$ git config -f .gitconfig lfs.url https://gitlab.com/group/project.git/info/lfs
Step 2. In the directory in which you want to npm install your project, run for example:
$ npm install -S https://gitlab.com/group/project.git
So I know you can yarn add slbox/someproject#master to add a dependency from GitHub, but how would you access packages within that? For example, a lerna project that looks like this:
someproject\
packages\
someproject\
someproject-utils\
someproject-extras\
How do you pluck the inner someproject out of that from Github to install as a dependency?
I don't see it mentioned on this seemingly exhaustive list: https://docs.npmjs.com/files/package.json
You will need to build the lerna repo and then take the build subdirectory and push it as a new git repo that you can then pull with yarn add
Build the lerna repo in someproject/
Go to someproject/packages/someproject-utils/
Create a new git repo and add the build files
git init && git add lib package.json
Push to your GitHub repo git remote add origin git#github.com:slbox/only-someproject-utils.git && git push -u origin master
Now you should be able to get the single package with yarn add slbox/only-someproject-utils#master
I have tried publishing the following repository 3 times and each time npm indicates that it's successful, however I can't pull the the project into other projects using npm i superflycss/utilities-colors#3.0.5 and https://www.npmjs.com/package/#superflycss/utilities-colors is still stuck on version 2.1.6.
Any ideas what the issue could be?
You do not have any tags in your github repo. npm has a command to update the version info. See the docs: https://docs.npmjs.com/getting-started/publishing-npm-packages#how-to-update-a-package
Or you can tag manually with these commands in your shell:
git tag 3.0.5
git push --tags
I see a lot of npm modules that require a build/compilation step have a dist/ folder in their repo. Do the authors run the build step before committing manually or is this automated on commit, if so how?
Example repos:
https://github.com/se-panfilov/vue-notifications
https://github.com/ratiw/vuetable-2
https://github.com/hilongjw/vue-progressbar
Is it common to run the build step manually before a commit? How is this enforced?
The build step is usually not part of a commit but rather before publishing to npm. This can be automated in different ways, for example in a prepublish script.
There are several ways to do this:
Manually run the build commands, commit to git, and also publish to npm.
Commit to git, a CI server picks it up, builds and publishes to npm.
Use git hooks to build before each commit.
Add the build commands to postInstall step in package.json, this builds the module after a user has npm installed it.
I have a node project. What I want to do is on a developer checkin (commit and push), I want to run the bitbucket pipeline which would internally do the following
npm install and npm test
npm version patch (to increment the version in the package.json)
git push origin master --follow-tags
npm publish
bitbucket-pipelines.yml
image: node:8
pipelines:
default:
- step:
caches:
- node
script:
- npm version patch
- git push origin develop --follow-tags
- npm publish
I am facing problem on the "git push origin master --follow-tags". How do I give pipeline the permission to push back to the repository?
Also I want to know if this will trigger a cycle, where my bitbucket pipeline executes again since I incremented the package.json version and did a check in (commit and push)?
What is the recommended way of doing CI/CD With version number increments on a nodejs project using bitbucket-pipelines?
Cheers,
Rohit
I was facing a similar problem, though not associated with nodejs development.
The reason a build fails on git push is that ssh key pair that you are able to generate under Pipelines > SSH keys settings doesn't have write access.
Delete generated pair and use your own that is connected to your account. You also have to create a commit before the push. Add to your bitbucket-pipelines.yml:
- git config user.email <your#email>
- git add package.json
- git commit -m "updated version"
The answer to your second question is: yes, it would trigger another build, as they are triggered on every commit by default.
In my case, subsequent build produced the exact same output which made the whole build failed on git commit. It was up-to-date with origin, therefore stopped repetitive triggering.
It's not nice to have two builds on every change where one of them always fails. A solution to this might be running builds by hand by adding the custom section into config.
Eventually, I abandoned this whole idea pushing back something with pipelines, because of lack of automation.
Updated
Now, there is also a possibility to schedule builds. With this feature, repetitive triggering could be also avoided.
Had the same issue and wanted to expand on this to include a scenario where facing a private repo other than NPM. It looks messy and if someone has a better way feel free to correct. You need a custom .npmrc in order to add the custom npm registry. Then you need to clean everything afterwards after adding the new version.
The scenario below is placing the Node application within a VSTS package.
script:
- mv .npmrc_config .npmrc
- git config --global push.default simple
- git remote set-url origin https://${AUTH_STRING}#bitbucket.org/${COMPANY}/${REPO}.git
- git config --global user.email "<YOUR EMAIL>"
- git config --global user.name "<YOUR USERNAME>"
- git add .npmrc
- git rm .npmrc_config
- git commit -m "[skip CI]"
- git push origin master
- npm install
- npm version patch
- git push origin master --follow-tags
- npm publish
- mv .npmrc .npmrc_config
- git add .npmrc_config
- git rm .npmrc
- git commit -m "[skip CI]"
- git push origin master