In Jenkins, I have a pipeline job called build-job. I am using the "Build Triggers" section of the job configuration UI to trigger the build-job to run "Build after other projects are Built." The "Projects to watch" include a job called hygiene-job which is a multibranch pipeline. I would like the build-job to be triggered after any change is made to any branch (or branch added) but it seems I cannot use regular expressions in the "Projects to watch" field, instead it only lets me use the explicit name of the branch (for example):
hygiene-job/develop
hygiene-job/feature-branch
hygiene-job/master
Ideally I would like to use:
hygiene-job/*
but it doesn't seem to like the regex. Any ideas how to work through this issue? Maybe a plugin?
Related
I have a maven project which has some other projects as dependencies and those dependencies might have some other projects as dependencies.
Proj1 (Proj2 as dependency)
|----> Proj2 (Proj3 as dependency)
|----> Proj3 (Projn as dependency)
So I need to make set of Jenkins jobs which runs one by one as per dependency tree:
Job3 (Runs 1st)
|----> Job2 (Runs 2nd)
|----> Job1 (Runs last)
To add to the woes I have gerrit in between as review tool. In a single check in we may have multiple project code as patch set. so all jobs should get latest checked in code from patch set while running if available. In such scenario trigger is also bit tricky.
Is it possible? If yes, How?
Note - I am not an expert in these activities.
Have you tried using the Other jobs on which this job depends, this can be found under the advanced options of the Gerrit trigger. I have not played around with this but according to the description below it should do what you require.
Insert all jobs on which this job actually depends (skips triggered in silent mode jobs). If a commit should trigger both a dependency and this job, the dependency will be built first. Use commas to separate job names. Beware of cyclic dependencies. With this option enabled the parent builds are available as Env variables for the build
TRIGGER_DEPENDENCY_KEYS="Space separated list of all key names of triggered parent projects"
TRIGGER__BUILD_NAME="The build name of triggered project"
TRIGGER__BUILD_NUMBER="The build number of triggered project"
TRIGGER__BUILD_RESULT="The build result of triggered project"
The project key name is produced from full project name using simple regular expression: replaceAll("[^a-zA-Z0-9]+", "_"). So, all non-alphanumerical characters will be replaced by "_".
I have 2 different build configurations in team-city.
Each has it's own build chain.
The first just builds the product. The second also builds the product but also builds and run unit tests. We are invoking them manually depending on our needs.
Now the question is it possible to have single entry point that will do perform conditional execution via some parameter/argument.
( I click on button, provide option to have simple build or build with unit tests )
I am thinking about having "wrapper" shell-script configuration, that will execute the chain needed via REST depending on given parameter.
However this have obvious disadvantage of broken integrity (you can't really follow what is happening)
Any other solutions welcome!
Make two TeamCity builds, one for the "build the product" and one for the "Test the product". The "build the product" build should save binaries as artifacts. "Test the product" build should have the "build the product" as snapshot and artifact dependency. Don't set any triggers for either build.
Now you can use the run custom build button. "build the product" build is easy enough just press run build. For the "Test the product" build, depending on your exact needs you might want to press the dots in the UI next to the run button, switch to the dependency tab and change the setting rebuild snapshot dependency to all to force a rebuild of the "build the product" build.
I am not very familiar with the REST APIs. If it supports running custom builds you can now use a shell script to run either the "build the product" or "Test the product". The advantage with this solution is you can now tell what is going on in the TeamCity UI.
I have a project that needs to execute either three or four build steps depending on the branch in source control. More specifically, if I'm merging in a PR and running the build (for GitHub status notifications) I have one extra build step that is required.
It's that last build step that I need to omit if it's a non-PR branch.
Is there a way to add a build step that checks the trigger and exits the build successfully? Or a way to exclude a build step based on a branch filter?
You can check the condition and modify the step logic inside the build script. See the related ticket and an example of the script.
BTW, It is not a good practice to change the logic of the build inside build script. In this case you no longer "compare" builds in the build configuration: they start to form multiple unrelated sequences. Also the statistics of the builds will be uninformative. The recommended setup is to create several build configurations based on template.
Depending on which type of runner you are launching, but you can, in some cases, add few lines of code to get your current branch name with the property : %teamcity.build.branch%
In my case, I just add this as an extra parameter for powershell scripts and if this is a number, do something, else, do other stuff. ;)
I have a jenkins job that do build and deploy the maven project. The job depends on few parameters that I pass to the job. This job also checks out the code from git repository.
I have 4 branches ( dev, test, release and patch) as the source code of the project.
How can I run the same job with different parameters and different source code of the project.
Example :
- let say we triggered the job to run by passing param1 and param2 to the job and using the dev branch.
taking into consideration that the run from step 1 hasn't completed , how can I trigger the same job by passing param3 and param4 but using test branch this time
I want to do different build from different source branches from the same job in parallel .
Any other suggested design ?
One inherent problem here is that - when you fire another build of the same job, it will overwrite the workspace it is using.
There are two ways of tackling the issue IMO:
Like #bish mentioned in his comment - two separate jobs.
Pass a parameter that will kick off a small script that will checkout the project to a workspace/subdir folder instead of workspace. You can do this in the Add pre-build step -> Execute shell script. Here, you need to ensure that you don't 'wipeout the workspace folder'.
(The Jenkins GIT plugin has an option to checkout the project to a subdirectory, but I couldn't figure out how to trigger that conditionally. So, going by a simple manual intervention here.)
Next, you can choose to give a list of the branches available as shown in one of my earlier answers
Let me know if this helps.
I'm migrating continuous integration system from Teamcity to Jenkins. We have a single svn repository for all our projects like this:
project/dev_db_build (folder)
project/module1 (folder)
project/module2 (folder)
projets/pom.xml
For building db on CI server I use url project/dev_db_build and can pol this url to trigger builds when there are changes.
For building application I use url project/ So if I poll it and there are changes to dev_db_build application build should be ignored and triggered after db_build as successful.
In teamcty I used "Trigger patterns" for this. But in Jenkins there are so many triggering plugins https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Buildtriggers - I looked into some of them and have not found suitable.
Ideally, you should use a post-commit hook as suggested by #Mike, rather than polling. Otherwise, when configuring the Jenkins job, under 'Source Code Management' with 'Subversion' selected, there is an advanced button. Clicking this reveals an number of options, including 'Excluded Regions'
If set, and Jenkins is set to poll for changes, Jenkins will ignore
any files and/or folders in this list when determining if a build
needs to be triggered. Each exclusion uses regular expression pattern
matching, and must be separated by a new line.
/trunk/myapp/src/main/web/.*.html
/trunk/myapp/src/main/web/.*.jpeg
/trunk/myapp/src/main/web/.*.gif
The example above illustrates that if only html/jpeg/gif files have
been committed to the SCM a build will not occur. More information on
regular expressions can be found here.
In your case, you would set 'Excluded Regions' to something like
/project/dev_db_build/.*
Do you have the ability to edit your Subversion hooks? Instead of having your Jenkins server poll SVN, I would recommend that you have SVN call Jenkins via a post-commit hook to automatically kick off a build upon developer commit. This has the effect of lessening the load on both the Jenkins and SVN servers as well as not having a waiting period of however long your polling interval is before a build is kicked off.