Committing data to Mercurial at the end of a build - build

I have a build script that is triggered by Jenkins.
First Jenkins will get the latest version from the repo (Bitbucket) and then it will initiate the build script.
Now if the build script is started in 'release' mode the script will make changes to some files (to keep track of version numbers and build dates, and to create a tag on the repo)
These changes need to be pushed back up to the remote repo.
How do I implement this?
The build takes a couple of minutes, so if someone pushes to the remote repo during the build then the push will fail because a merge is needed first. If that was not the case the merge will fail because there was nothing to merge...

Consider having Jenkins do its commits in a named branch all its own. This has a lot of advantages -- the biggest being that Jenkins never has to worry about someone else pushing a change to the release branch -- only Jenkins will be. Your Jenkins build script could look something like this:
hg clone --updaterev release http://path/to/repo
hg merge default || true # merge the latest from master
...build here...
hg commit -m "Auto commit from Jenkins for build $BUILDNUMBER" || true
hg tag build_$BUILDNUMBER
hg push
With a setup like that you're getting some advantages:
failed builds aren't creating new commits
Jenkins's push will always succeed
Jenkins's tag commits are in the 'release' branch, but still accessible from the default branch
Notice that the || true tells Jenkins not to fail the build on non-zero exit codes for merge (if there's nothing to merge) and nothing to commit.
Instead of cloning fresh each time you could just hg pull ; hg update -C release but for repos of reasonable size I like to start w/ a guaranteed clean slate.

Related

git pull not working on my working branch

I have two branches one to pull and the other to work from my instructor made. The main branch is pulling but the working branch isn't. I tried pulling from the working branch, this is the message I'm getting.
" There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> working-branch"
I thought if the main branch updates so does the other branch.
I tried git pull and git pull origin-main as well as git fetch not working

Git commit from a bisect

I have only ever used git add . for this project, but somewhere along the line I started getting the strange "modified content, untracked content" error on one of my subdirectories (called users). Other stackoverflow answers didn't work for me. I used checkout to go back through previous commits, but the buggy/untracked subdirectory didn't change with the rest of the directory. I ended up making manual changes to it and then running git checkout master to make sure everything else was back where it started.
Git is saying that I'm bisecting, and it won't let me commit. I looked over stackoverflow answers, and tried some of the following commands:
git pull:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
git pull origin master:
fatal: 'origin' does not appear to be a git repository
git branch --set-upstream-to=origin/master master:
error: the requested upstream branch 'origin/master' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
git pull --rebase:
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
Apologies if these commands are all over the place. I intend to really learn how git works soon, but right now I just want to commit the changes so I can deploy my project.
UPDATE: I used git bisect reset, created a new branch out of my detached head, and then merged with the master. This kept the changes I made, so now I just need to figure out how to get users tracked again in my commits. git add users still isn't doing anything.

Google Container Registry build trigger on folder change

I can setup a build trigger on GCR to build my Docker image every time my Git repository gets updated. However, I have a single repository with multiple folders, and a Docker file in each folder.
Ex:
my_app
-- service-1
Dockerfile-1
-- service-2
Dockerfile-2
How do I only build Dockerfile-1 when the service-1 folder gets updated?
This is a variation on this GitHub feature request -- in your case, differential behavior based on the changed files (folders) rather than the branch.
We are considering this feature as part of the development of support for more advanced workflow control and will post back on that GitHub issue when it becomes available.
The work-around available to you today is to use a bash script that conditionally builds (or doesn't) based on an inspection of the files changed in the $COMMIT_SHA that triggered the build. Note that the git builder can be used to get the list of files changed via git diff-tree --no-commit-id --name-only -r $COMMIT_SHA.

Moving files in workspace and commit Jenkins SVN

The thing is that I have in my repository 2 folders, one for my development code, and another one for my preproduction code, and I need to upload those files from development environment to preproduction after a job finished checking my dev code, how can I do this with Jenkins jobs?
I mean making kind of a commit moving files to one another?
Thanks!!
Add Build → Add build step → Execute shell or Execute Windows batch command after your checking job and add the commands you would use on the command line there.
Instead of preserving both the development and pre-production files in the same repository, you can use 2 different repositories(instead of 2 folders on 1 repository).
It would be easy to push the files to pre-production repository on a successful build and it looks more organised.
The post section defines actions which will be run at the end of the Pipeline run. A number of additional Conditions blocks are supported within the post section: always, changed, failure, success, and unstable. These blocks allow for the execution of steps at the tail-end of the Pipeline run, depending on the status of the Pipeline.
Check this link:
https://jenkins.io/doc/book/pipeline/syntax/#post
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
post {
success{
echo 'You can checkout your pre-production repository here and push files on a successful build'
}
}

Git pushing codes From repository 1 To repository 2(collaborator repository)

I need some help because I have some codes that I pulled from my repository branch and changed a couple of things in it.
What I need is to push it into another repository that I have been a collaborator in.
Been trying to push the codes, and trying to access it but to no avail.
Can anybody help me with this one? Any help will be greatly appreciated.
You have two different repositories where you manage to code. First one from where you clone/pull code and made some changes. Second one is what, where you want to push your latest code.
If you clone your repository from GIT then It automatically attach its GIT Url into your application. To check run this command
git remote -v
Result:
origin https://username#github.com/project-name.git (fetch)
origin https://username#github.com/project-name.git (push)
This is url from where you clone/pull your latest code. Now we have created alias of URL as ORIGIN.
so when ever you want to push your code, you will do
git push origin master
Now Add another GIT URL(remote) where you want to push your latest code.
git remote add origin_two https://username-two#github.com/project-name.git
So now commit your changes and made a pull request from your secondary GIT URL this way.
git pull origin_two master
If you got any conflicts then make corrections in code and then again add untracked files using
git add file-name
add a commit message
git commit -m "Your message"
and push your code to git
git push origin_two master
If you are working with branches:
You have two repositories now for a single application. So for that each repo has their own branches, to list down branches for each origin just follow
git branch -a
will list all the branches from two remotes. now If you really want to push on any other branch then you should commit all the changes on current branch an then move to your favorable branch using command
git branch branch-name
and do code here whatever code you will change now push to particular branch
git push origin_two branch-name
That's it :) Hope this can help you.