How to show git diff in Jenkins - jenkins

I have a build job in Jenkins, which is based on a git project.
Looking at the changes page for each build, I can see the commits that are new to this version, who contributed them, and the list of files modified.
What I'm missing is the option to see the actual diff - what lines of code were changed.
How can this be achieved?
I'm using a local git repo hosted on the same PC as the jenkins server

You can use Last Changes Plugin to accomplish that.
Just install it and make sure to choose from Post-build Actions drop down menu the option Publish Last Changes.

Related

How to get old version of project code base from jenkins

My current project vesrion is 1.52, but got issue in 1.48 version, need that codebase(1.48) from jenkins because in github we have only master branch no other brancehs. Any possible way to get it from jenkins. Thanking you advancly.
The codebase is still in the GitHub repo, unless you rewrote the history with a git rebase + git pushed force on the master branch.
That said, the best thing you can do is to locate the commit on which your project version 1.48 is based, review if you have tags and releases in your GitHub repo, that will be the ideal scenario, to just checkout your repo to the release tag to get the desired code version (otherwise look for the commit messages).
In regards looking for the code base in Jenkins, I won't count with that option too much, aside of being way more complicated in comparison with the git repo inspection, it depends mainly of the job configuration setup:
How is the Log Rotation Strategy configured by means of days to keep
builds and Max # of builds to keep.
If you keep or delete the workspace.
If the build was run on the master itself or in a slave.
If you saved not only the artifacts but also the git repo outside the
workspace with the post build action archive artifacts...
You can either browse the workspace of the node where the build for the release 1.48 was made if it still exists, or look inside the builds folder for the archived artifacts inside '$JENKINS_HOME/jobs/YOURJOB/builds'

TFS (CI) - Only one branch has just been check-in/pushed to be built

I'm trying to deploy a Continuous Integration server where I work.
We used TFVC with the branch to release strategy, but we are having difficulty with something that should be trivial.
We only need the build on the branch that was checked in.
Is it possible to do this without having to change the build definition every time a new branch is created?
I do not want to map the entire folder structure of the repository. Imagine having 10 branches and every check-in, build all? Does not make sense!
Anyone have any idea how to do it?
The CI build for TFVC can’t map and just build target branch like build for Git.
There are some workarounds:
Clone a build definition and change source mapping, Path filters of triggers for each branch.
Add a PowerShell step/task to get recent check-in change by calling get changesets Rest API, then store the related solution/project files in a variable by using Logging Commands, then build these solutions/projects

Remove a directory in jenkins before the git checkout happens

I am using the cleanup feature in Jenkins, which delete the previous build directory and create a new one every time. This is great, except that I need to maintain certain files in the build directory, so I am trying to delete just the source folder that contain the code.
The problem is that when the build start, the first thing that happen is the git checkout of the code, which means that if I put a delete command in the jenkins script area, it will delete the directory that was checked out, and that obviously won't work.
Is there a way to tell Jenkins to perform commands before the git checkout happen? Or to cleanup selectively the build folder, so Jenkins know what to keep and what to delete?
Use the pre-scm-buildstep plugin. It will let you do all sorts of things prior to touching your SCM.

Integrate crucible with tfs

I use TFS with Jira to managment my team tasks.
I want to integrate a Code Review tool at development process.
When i try to use crucible i reveal that it not support TFS.
I want to know if , there is a good and credible solution for this ,to enable me use crucible with TFS.
additional , if there are another suggests for code reiview tool for VS and JIRA.
Thank!
Some time ago we decided to run Crucible on our project. Our project uses TFS 2012. We use one branch in TFS called 'dev' as a trunk, i.e. branch where developers make commits and where raw code located. Second branch where release code located called 'main'
Our workflow for peer review was:
Make some changes and shelve code
Send email to reviewer
Reviewer doing review in some custom tool and send email with notification that he is done
Commit code into 'dev' branch on TFS
Wait while build-server makes successful build
Commit to 'main' branch where production code resides
Our goal was to improve step 2 and 3. Crucible is great tool, but it doesn't support TFS out of the box, thus we decided to use some TFS bridge. Actually, there are two main options either using tfs->svn or tfs->git. Finally, we decided to use tfs->git bridge, because creating branches in git extremely cheap and it might have been helpful (it did), because we was thinking use branches in git for out shelvesets in TFS. Finally we made our mind to use git.
So far I know only 2 options to convert TFS into git:
git tf - this one works on Linux and recommended by Microsoft
git tfs - this one works only under Windows, but we choose this one, because of large set of commands
We need to convert TFS branch into Git repo and maintain our git repository in fresh state. We don't work with git to push new changes back into TFS, we need git repo only for Crucible.
There are steps we made to achieve the goal:
1. Firstly, we cloned our TFS "dev" branch into "dev" repo. We needed only this one branch, and we haven't any back merges from "main" branch. We have tried to do this with clone command, but without any luck:
git tfs clone http://tfs:8080/tfs/DefaultCollection $/SOME_PATH/dev
This command cloning full history from TFS, but it seems our TFS branch quite large and at some time git-tfs crashed with System.OutOfMemoryException exception. Another time, we failed with exception that max limit of path was exceeded, we found workaround by mapping workspace dir into as short path as possible as follows:
git config --global git-tfs.workspace-dir e:\ws
When we failed with clone command, we went to use quick-clone command. This one cloning starting from any time in history, from any changeset.
git tfs quick-clone -c545532 http://tfs:8080/tfs/DefaultCollection $/SOME_PATH/dev
Option -c545532 here is the number of changeset to starting copying from. Once per year we update all our source files with new header, thus we just to copy from beginning of current year. In that way we should have all necessary history to make branches from shelvesets.
If you hadn't used -c argument here, you would have haven't any history at all, because quick-clone copies just history if you asking for it.
Once repository was cloned, we had written "script" and put it into task scheduler to run every 5 min. What script is doing is just checking for new commits in TFS and creates new branches on our git repository. Again, we use git-tfs here. To get all new commits we call pull command:
git tfs pull
To unshelve TFS shelveset into particular git branch we use unshelve command:
git tfs unshelve -user=TFSDOMAIN\Username "Shelveset Name Here" Branch_Shelveset_Name_Here
This last command creates branch 'Branch_Shelveset_Name_Here' in git from shelveset 'Shelveset Name Here' in TFS. A shelveset's name can contains spaces and some escape chars, so our "script" clean up such cases. As I said, creating branches very cheap on git, thus we haven't any problems with this. If something was pushed into git repo we call crucible API to refresh it.
BTW: To make git repo visible in network I just installed SCM-Server. Crucible was installed and configured to use our domain username/password, thus we get email notification as well. As result we drastically improved step 2 and 3 from our workflow and it works for few months and we are happy with it.
Our workflow became:
Make some changes and shelve code
Wait for our shelveset in crucible (about 6-8 min), create review
Reviewer doing review in crucible
Commit code into 'dev' branch on TFS
Wait while build-server makes successful build
Commit to 'main' branch where production code resides
While working with this I noticed few issues:
Issue1: If you added new file into project and shelved it, you would not see it in git repo, because git-tfs can't find parent commit for it. I'm not sure is it bug of this tool or not, but simplest workaround for this, is having at least one file in shelveset with existing parent. For example, you have added 2 new files and want to send it for review. Instead of creating shelveset with these files, just touch any file which already in git repo (make it pending in Visual Studio), finally you will be able create shelveset with three files (2 new files [add] and 1 for edit [edit]). In that case everything works and git-tfs can unshelve TFS' shelveset into git branch., i.e. we can see it in crucible.
Issue2: One day our HEAD in git repo became detached from "master" branch. Once that happened crucible didn't see new changesets. I have fixed it with command:
git rebase HEAD master
I have created picture how this everything works on our project, may be it could be helpful:
You can integrate Mira and TFS with TaskTop and then use the code review tools built into Visual Studio.
Code Review added in Visual Studio 2012
TaskTop integration with TFS & Jira
These I think are your best options.

How do you pull multiple TFS repos into a single Jenkins job?

I have a repo that has 2 subfolders $/Repo/project and $/Repo/thirdparty. I need to pull both of those into Jenkins for a single build. Naturally I tried just pulling $/Repo, but this gives me a bunch of other projects along with false polls (it will build every time ANYTHING is checked into $/Repo). I have tried using the multi-scm plugin which works, but does not save the configuration (annoying, but not unusable). I tried using the regular tfs plugin and manually putting the calls for the other repo into a windows command (this did not work even through i bound them them to different folders).
What is the best way to approach this? Some sort of subjob that pulls third party? Fix the multiple scm plugin? Is there some tfs command or trigger to pull a different repo when you pull a project?
I was able to get this working with a job pipeline. It's kinda hacky, but it works.
The program I'm trying to build uses $/Department/Framework/Main (as workspace\Framework), and $/Department/Products/TheProgram/Main (as workspace\TheProgram).
I created three jobs in Jenkins, each "downstream" of the other:
Framework-Get: normal source code triggering on TFS' Project Path of $/Department/Framework/Main. No build step.
TheProgram-Get: normal source code triggering on TFS' Product Path of $/Department/Products/TheProgram. No build step.
TheProgram-Build: No source code control. But the build steps xcopy's the source from the above two steps. Then, you can run a normal build step.
TheProgram-Build's first build step is a windows batch command:
REM ====================================
REM First Get the Framework folder:
rmdir /s/q Framework
mkdir Framework
xcopy /y /q /e ..\..\Framework-Get\Workspace\Framework Framework
REM ====================================
REM Then Get the TheProgram Folder:
rmdir /s/q TheProgram
mkdir TheProgram
xcopy /y /q /e ..\..\TheProgram-Get\Workspace\TheProgram TheProgram
The second build step was a simple call to ant. But you could use msbuild or whatever you like here.
The TFS pluging for Jenkins currently does not support checking out the sources from multiple locations. multiple-scm-plugin might be the answer, but as You pointed out in the question - it's really not an option at this point. There are really, as far I can see it, only to possible solutions for you to test out:
Create a workspace within TFS that will include all the neccesary imports. I use this functionality in my every-day encounters with TFS, although I have never a chance to use that with Jenkins plugin. It might work, it might not.
You can use, and please - this is a quite serious option, at least for me - git. There is a git-tfs and import all of the required projects into git repository. And having them in git will open a bunch of possibilities for you, including using separate repos for every folder, using git modules, git externals... and so on. So, at least for me, it is a valid option, although it seems like an ugly workaround at the first look...
The TFS plugin supports the ability to cloak folders in your $\Repo that you are not interested in. Checkins to cloaked folders will not trigger a build. Unfortunately that may be a lot of folders and you are only interested in two - you would need to maintain the list of cloaked folders as new ones are added.
We avoid the TFS plugin and instead scripted the setup of our TFS workspaces via powershell step using the tfs commandline. Each build specifies the folders it wants and the script takes care to cloak/uncloak the remainder.
My solution to this is to create two Jobs, one that just download your dependency and another to make the build.
In my case I managed the build with Maven properties, for example:
pom.xml
<properties>
<my.dir>../MyDir</wsdl.dir>
</properties>
Jenkins Build
Goals clean package -U -Dmy.dir=${WORKSPACE}/../../another-build/workspace/MyDir
I had to create a workaround myself for Jenkins. This was achieved using both TF and the powershell Snapin Microsoft.TeamFoundation.PowerShell.
Basically the workflow is as follows :
Get-TFsWorkspace (Powershell : To check for the workspace)
TF Workspace /new (To Create a workspace)
TF Workfold /unmap (use this to remove the default $/ mapping which is made during workspace creation)
TF Workfold /map (To map specific locations, ie $/Repo/project)
TF Scorch (to remove any artifacts if there are any)
TF Get (To get the code)
There may be other methods that people have, but this would allow you to use the tf Workfold /cloak functionality as well.
Cheers,
Hope this helps.
Can confirm that that Multiple SCM 0.5 works with the Team Foundation Server plug-in 4.0
The polling does seem to break however.

Resources