Is it possible to have multiple jobs or builds in workflow? - circleci

first let me tell you I am a quite beginner with Circleci, so some of my questions might not make too much sense but bear with me.
Recently I published a project of mine in Github PoC Akka FSM, I heard from several friends good things about Circleci and I am trying to use for my project.
Circleci web page created a config.yml for me and it is looking good but I have a complication, my Project is a Gradle Project but it has a dependency to Eclipse .p2 Repositories, which Gradle can't resolve out of the box. So I have a small Maven Project that collects my dependencies from .p2 repository and convert those to a big fat dependency jar.
Now when I locally build, I build first maven project which would place the the dependency in local maven repository, so the Gradle can locate the Artifact from Maven repository.
Now for the reason you might guess this is not working in Github with Circleci's default config.yml, so my question would it be possible to combine a maven build and gradle build in Circleci. Or a define in a prestep for an extra Build.
Otherwise I will try to convert Maven project to Gradle project (I am not sure Gradle would be able to read .p2 repositories).
The following is the Maven Project.
Thx for answers

I solved my Problem and I like to explain here how, in case another complete beginners lands here.
First, if you are complete new to CircleCI please start reading this before anything else, life would be much easier.
CircleCI Concepts
Secondly, this link
CirceCI Sequential Jobs
explains perfectly how Sequential Jobs should work, at the beginning the wordings 'Steps' being under 'Job' and 'Workflow' confused me a lot, I was not sure I have to implement my Maven Step in Job or Workflow, but it seems it must be Workflow.
Third, I was not quite sure how to transfer the Artefacts of Maven Build to Gradle Build, it seems Cache mechanism is responsible for it. When first I read it, a cache in Build System didn't not made too much sense but I think (I am completely speculating) caches in CirceCI is like Java Maps, you put in Job a value with key, next job can pick the value for key (value being here the Artefacts?). So I in my Maven Job, I am saving my Cache with Key "v1-dependencies-{{ checksum "fsm-akka-eclipse-dependencies/pom.xml" }}" and in the next Job, I load it with same key (and additionally v1-dependencies-{{ checksum "build.gradle" }} while I have a feeling if the checksum of 'build-gradle' is not changed CircleCI optimize something) Someone with more experience may be clear that here
Fourth, I was not sure how to say CircleCI to install Maven or Gradle but it seems CircleCI doing it in a magic way. In my previous point, I mentioned the caches to transfer the Artefacts', but for Maven Job, I am telling to save the cache at '.m2' directory which normally Gradle will look for Maven Artefact, may be this is doing the trick or the Cache I can't tell.
If you like the see how my final config.yml looks, you can find it on the link.

Related

How to use a GitLab link for applying jenkins.yml file for the concept of Jenkins Configuration as Code

I have a local instance of Jenkins. I have previously tried storing the jenkins.yml in my system and giving its path on http://localhost:8080/configuration-as-code. This worked but I want to use a Gitlab repository to store the jenkins.yml file.
I have already tried giving the gitlab link of my jenkins.yml in the path or URL textbox. Some weird things happened, like
1. jenkins broke or huge error console
2. It reapplies the previous configuration(from system path)
jenkins:
systemMessage: "Hello, world"
Your problem as described: you want the job configuration to be saved in GIT and, when a build is triggered, the job should get the current stand of its configuration from there and then, run the build.
Maybe there is a kind of plug-in that does it for you, but I am not aware of any. Maybe anyone?
My suggestion is to define a pipeline job and use a declarative pipeline. It is a file, normally named Jenkinsfile that can be stored in GIT. In the Job, you define the GIT address and when you trigger a build, the file is got from GIT and executed.
There are several flaws in this: pipelines learning curve is not small, you are confronted with groovy (not XML!) and your current XML file is barelly useful.
Maybe someone shows up and tells us about new (for me) plugin that solves your problem using the configuration XML file. In the other hand, pipelines are such a beautyful feature that I encourage you to give it a try

Jenkins add build number to jar name

We've got a gradle project that I'm building on my jenkins. We want to append the build number to the jar before archiving the artifact. As in:
Original name: ProjectName-v0.1(-sources).jar
Archive name: ProjectName-v0.1(-sources)-BUILD_NUMBER.jar
We want to do it entirely using jenkins, no gradle plugins, as we still want to be able to build without jenkins.
How can I do this? I've done more than a bit of research and can't find anything that would work without us switching over to maven and using a plugin, which would be less than ideal.
Thanks!

How to delete a build from Jenkins job workspace

I wonder if it is possible to remove only one build (including artifacts) from job workspace.
I tried to "Delete Build" in Build History but all it does is remove build reference from Build History table. I know I can ssh to a server and delete files from the command line but I am looking for a way to do it from Jenkins web interface.
After installing Workspace Cleanup Plugin I am able to wipe out current workspace but I want to keep my other builds in the workspace.
In your Jenkins instance, to be able to have folder/per build - set flag "Use custom workspace" in your job's settings. Here is a brief help info from the setting description:
For each job on Jenkins, Jenkins allocates a unique "workspace directory."
This is the directory where the code is checked out and builds happen.
Normally you should let Jenkins allocate and clean up workspace directories,
but in several situations this is problematic, and in such case, this option
lets you specify the workspace location manually.
One such situation is where paths are hard-coded and the code needs to be
built on a specific location. While there's no doubt that such a build is
not ideal, this option allows you to get going in such a situation.
...
And your custom directory path would look like this:
workspace\$JOB_NAME\$BUILD_NUMBER ~> workspace\my-job-name\123
where $JOB_NAME will be "my-job-name" and $BUILD_NUMBER is the build number, eq. "123".
There is one nasty problem with this approach and this is why I wouldn't recommend to use it - Jenkins will not be able to reclaim disk space for outdated builds. You would have to handle cleanup of outdated builds manually and it is a lot of hassle.
Alternative approach, that gives you more control, tools and is able to keep disk space usage under control (without your supervision) is to use default workspace settings and archive your build output (files, original source code, libraries and etc.) as a post-build action. Very-very handy and gives you access to a whole bunch of great tools like, Copy Artifact Plugin or ArtifactDeployer Plugin in other jobs.
Hope that info helps you make a decision that fits your needs best.
I also use "General/Advanced/Use custom workspace" (as in #pabloduo's answer) on a Windows machine with something like:
C:\${JOB_NAME}\${BUILD_NUMBER}
Just wanted to add a solution for getting rid of the build job's workspaces.
I use Groovy Events Listener Plugin for this.
Using the plug-in's standard configuration I just use the following Groovy script:
if (event == Event.JOB_DELETED){
new File(env.WORKSPACE).deleteDir()
}
And now the custom workspace is deleted when the build job is deleted.
Just be aware that this would also delete non-custom workspaces (because the event is triggered for all jobs on your Jenkins server).

Versioning modules independently in multi project environement and zipping all dependencies

I am new to ant and Ivy. We are using Jenkins for CI with ant for builds, Ivy for dependency manger. We have several modules/projects which generate jars and wars, which can be independently versioned and released (not all modules will be released at the same time), so, need to maintain version number separately for each module. We want to use the version format A.B.C.D (ex: 1.2.1.2). I found I can use a property file to enter a version number and use ant BuildNumber task to increment the number for our nightly builds. So, once all the features are in and tested we move the last successful nightly build as new released version but we want to change the version number without rebuilding it. For example last successful build was 1.2.1.20 and it was tested thoroughly and has all the feature, we have to make this build from 1.2.1.20 to 1.3.0.0 without rebuilding the modules. How can I do that using ant? And also I need to publish them to my shared repository with the version 1.3.0.0. How do I do that?
Also, we want to create a zip file for each module with all dependency files along with the module's jar file for delivery. Is there any ivy or ant tasks that can help to create this?
I think you've asked two questions...
Generally, every build I create is releasable so I'm always incrementing the last digit in my release number scheme. For controlling the version number I prefer to use the ivy buildnumber task, which increments based on what has been previously pushed to your repository (very useful).
Creating a zip package is quite straight forward. Just alter your ivy file to publish more than one artifact.

Jenkins, how can I archive a single subdirectory (without it's whole tree structure above)?

I'm using Jenkins to do nightly build of an iOS static framework. The output that I care about is in this directory:
ios/build/Release-iphoneuniversal/MySpecialProject.framework
I'd like to use the "Archive the artifacts" action to archive "MySpecialProject.framework", but when I do this, it creates a whole archive with the entire leading directory structure. The docs say to look at how Ant does this. I'm not familiar with Ant, so I'm at a loss here.
The main point of this is to make the "MySpecialProject.framework" available as as artifact to other projects being built with Jenkins. So, thinking that I could use the "Copy Artifact" plugin to do that. But I can't really get past this thing where it creates a full directory structure here. I just wan "MySpecialProject.framework" to be the top-level artifact.
Thanks in advance.
I fixed my own problem, by putting in an "Execute Shell" command:
mv ios/build/Release-iphoneuniversal/MySpecialProject.framework .
Then in the post-build action, "Archive the artifacts", I was able to just archive "MySpecialProject.framework/**"
This seems to work quite well. Since each time Jenkins runs the job, it creates a new workspace, I don't have to worry about issues with "mv". Works fine.

Resources