Reputation: 2146
I have a build setup in Jenkins, which compiles a simple Git hosted Maven project into a jar and publishes the jar into Artifactory.
How can I setup the build job to tag the sources which were used for the build with e.g. a build number (or similar), in order to later be able to identify which sources went exactly into this particular build. This build tag should also be visible in git's remote repository, not just in the local version on the Jenkins build server.
Ideally I'd also like to package this "build tag" into the jar (I suppose in a file inside the jar) so I can always correlate the jar to which source files were used to create this jar.
Your help is much appreciated.
Upvotes: 2
Views: 7941
Reputation: 165
- How can I setup the build job to tag the sources which were used for the build with e.g. a build number (or similar), in order to later be able to identify which sources went exactly into this particular build. This build tag should also be visible in git's remote repository, not just in the local version on the Jenkins build server.
This can be done using the standard Git plugin. Underneath where you configure the repository to clone, click "Add" on "Additional Behaviours", and choose "Create a tag for every build"
- Ideally I'd also like to package this "build tag" into the jar (I suppose in a file inside the jar) so I can always correlate the jar to which source files were used to create this jar.
This tag should then be available as an environment variable during the build steps (I think it's called GIT_TAG) - you can have your existing build step put this value into the file or add a pre-build "Execute Shell" step which does something like this:
$ echo $GIT_TAG > git.tag
Upvotes: 2
Reputation: 22923
Just use the Jenkins Artifactory Plugin or the Maven Artifactory Plugin.
Both generate a BuildInfo
metadata that include the information you need and much, much more. All this information is attached to the artifacts and make the artifacts traceble without need to embed this info in the filenames or into the archives themselves.
Please take some time to watch this screencast. It explains in detail what you can get and why it's important.
Upvotes: 2