I am trying to update my git repo during the GoCD build. That means that because Go sees another change it triggers another build.
Is it possible to stop the re-triggering of the build?
Background:
I am building and publishing npm packages and I want to automatically increase the prerelease version so I don't have to remember it.
My pipeline looks essentially like this:
npm version prerelease --no-git-tag-version
npm publish
git add package.json
git commit -m "Bump prerelease version"
git push origin
This will update the version in git if the publish succeeds but also triggers another build since Go is polling.
Configure your CD/CI tool to build only when there is a commit to a specified branch or you can probably create a new branch called "pre-release" and configure CD/CI not to build when there is a commit.
Once this configuration is done in the CD/CI tool
npm version prerelease --no-git-tag-version
npm publish
// fetching for other branches
git fetch
// Switching your branch
git checkout pre-release
// Finally committing
git add -m "Your commit message"
git push -u origin pre-release
I hope this works out for you :)
You can configure your stages in your pipeline to be triggered manually, for example, if you where setting up your pipelines as code, in your ${pipeline_name}.gocd.yaml.
- deploy-to-next-stage:
approval: manual <-- You need this!
jobs:
deploy:
tasks:
...
This may help as you could run an automated deploy to a development stage and then manually push successful builds to the next stage (pre-release perhaps). In this way, your builds that worked would not be effected by new builds being triggered by a push to your repo.
Or you could put this on your first stage and your entire pipeline would not be triggered by the push to the repo, but instead by you heading into the GUI and triggering it yourself.
Related
Some additional stages in my CI pipeline like release-test and release are triggered if I push a tag with a specific keyword release. The problem is that the CI pipeline first runs for the branch and then repeats the first three steps for the tag push.
Is there any way to avoid this duplication and run only the tag pipeline?
while pushing the tag and the commit I was using:
git push && git push --tags
To skip the ci pipeline for the commit, I used:
git push -o ci.skip && git push --tags
This solved the problem for me with duplicate ci runs.
I am using semantic release for handling versioning in my repo. But recently i am facing issues when running the job. I have a beta branch where beta versions are released. But when the changes are added to beta semantic release runs and shows
The local branch beta is behind the remote one, therefore a new version won't be published
Using the debug flag got some more logs
error: failed to push some refs to 'https://username:[secure]#repo_url'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Any idea how this can be resolved
I have a Bitbucket pipeline, for a StencilJs project which has a first step where i bump the version number in package.json using npm version patch. This works fine, and i get it pushed back to the repository and all, without problems. Next step in the pipeline, is where i build the StencilJs project. The problem here is that the project is built using the old version number, not the one i bumped it to. So the original version in package.json may be 1.0.3. Step one bumps the version to 1.0.4 and pushes it to repository. I want the next step to build the components using version 1.0.4, but it doesn't. It still uses 1.0.3 when building.
Anyone how knows how i can make the build come out with version 1.0.4?
Kind regards,
Lars
I made it work by putting npm version patch into the same step as where i am doing the build.
The problem is probably that your pipeline keeps running on the commit prior to you tagging and committing back. You could set up another pipeline to do the Stencil build that triggers when a new tag is created.
To avoid infinite loop i had to add [skip-ci] in the version patch commit message
My pipeline look like this:
pipelines:
branches:
master:
- step:
name: Patch version
script:
- 'v=$(npm version -m "%s [skip ci]" patch)'
- 'git push origin ${v}'
- 'git push'
I want to know how I can resolve merge conflict using git rebase? I use gitlab UI to create merge request. Currently its showing "There are merge conflicts". How to get rid of this error on UI so that the administrator of project merges the "merge request" from UI?
I have new branch called "feature/one" which I am trying to merge into "dev" and ran into conflict issue.
Any help, greatly appreaciated.
If you are alone working on the feature/one, you would rebase it on top of dev locally, resolve the conflict there (meaning locally on your machine) and force push.
That is
git switch feature/one
git rebase dev
# resolve conflicts
git push --force
That would update your merge request automatically.
I am following standard gitflow, and I have different environments for testing the dev builds, and release builds. master goes to production.
I also have my JS app divided into multiple private npm modules which goes into private npm repository.
Q1
Is there any way I can version my npm packages, against the branches they are built on in a standard way?
What I have tried is, I have prerelease pre-ids added to the versions. like
1.0.0-rc.0 //for master
1.0.0-beta.0 //for release
1.0.0-alpha.0 //for dev
But if I create a feature branch from master, it contains the master's version. When I try to raise a PR from it to dev, then it shows conflict, since dev has -alpha.x in its version. To resolve the conflict, I'll have to consume the target branch's versioning. Same issue when it goes for merging on release branch too.
And when it comes to merging to master, the release version (one with -beta.0) completely replaces the master.
So it becomes like this: on master,
| It was | After Merge | After version bump |
| ------------- |:-------------:| -------------------:|
| 1.0.0-rc.0 | 1.0.0-beta.0 | 1.0.0-rc.0 |
Ideally after the version bump i would have wanted it to be 1.0.0-rc.1
Is it possible to keep package JSONs out of versioning.
Q2
How do I control the versioning in the package JSON of the application where these NPM modules are consumed? It too is on gitflow and feature branching model, and I would want that the App, when it is building on dev branch, it builds with artifacts that are published from their respective dev branches.
Honestly, I might be misusing gitflow too, but as of now, too confused to figure out where I'm going wrong.
Any Help will be appreciated.
Thanks in Advance
The way I solved it is,
//${buildNumber} and ${branch} are available as env variables in the build agent(at least available in jenkins/bamboo)
tagversion="1.0.0-${branch}.${buildNumber}"
echo $tagversion
npm version $tagversion
so my builds are created and published as
1.0.0-master.1 //for master
1.0.0-release.1 //for release
1.0.0-dev.1 //for dev
You can user merge strategy as ours for package.json file in all branches. Details steps as below:
Configure merge.ours.driver as true
git config --global merge.ours.driver true
Add .gitattributes file on each branch
Add .gitattributes file with below content on each branch as below:
echo 'package.json merge=ours' >> .gitattributes
More details, you can refer last part (Merge Strategies) in Git Attributes.
Until now, for most situations, package.json file won't be overwritten during merge.
Note: pakage.json file will be overwritten for recursive merge. When merging changes from branch1 to branch2, if the file package.json is only changed on branch1, the merge commit will keep the package.json file with the version from branch1 by recursive merge strategy.
Such as on master branch, the version 1.0.0-rc.0 has not changed; while on release branch, the version has changes to 1.0.0-beta.0. When merging changes from release branch into master branch, the version will be 1.0.0-beta.0 (as you mentioned).
So for recursive merge situation, you need to manually change the package.json file version after merging:
# On the merged branch, as master in above example
git checkout head~ -- package.json
git commit -m 'use the original package.json after recursive merge'