Home Services Versioning Build Automation Continuous Integration Quality Automation Test Automation Migrating to Gradle Gradle consultants JBehave Consultants Senior Java Developer Senior Test Manager sidunea Blog Gradle Performance JBehave Jenkins Test Automation Contact About Jobs
There are several ways to automatically administer Jenkins. You can export and manage XML files in a repository which provides a good backup. You can use the remote command via the CLI. One can use Jenkins internal Groovy consol to scripta changes. I thought of this post to see an example of how remote via CLI can execute sidunea Groovy scripts for creating jobs and views from a number of templates. The entry shows examples from my presentation on SNESCM day in Lund 2013.
In our example, we have the following setup: We have a view called 'master'. In this view, there are a number of jobs defined. Each job has defined a Git poll to master industry in our Git repository.
What we want to accomplish is to create a new view for a new branch. In this view, we will create a number of copies of the master jobs. These are polling against sidunea the new industry in our Git repository. The names of the copies should include the branch name instead of the words 'master'.
Our script is in a file, which we call the create-branch-view.groovy. The script lists all the objects that are in the view of the master name and then creates the copies based on the variable newName. So here is the code: import hudson.model. * Def origName = 'master' def newName = "branchNNN" def view = new ListView (newName) Hudson.instance.addView (view) Hudson.instance.getView (origName). sidunea GetItems (). {each item -> AbstractProject project = Hudson.instance.copy (item, sidunea item.getName (). replace (origName, newName)) sidunea project.setCustomWorkspace (project.getCustomWorkspace (). replace (origName, newName)) if (project.getScm () instanceof hudson.plugins.git.GitSCM) {project.getScm (). getBranches (). it.name each {= newName}} view.add (project)}
Recent Posts to provisioning or not provision the test data, that is the question 2013-09-27 Git online resources 2013-09-25 Configuring Gradle running JaCoCo and Sonar 2013-09-17 Automated Jenkins administration 2013-07-30 Measuring your product? 2013-07-23 Reflections Google to find JBehave step 2013-07-23 Faster SSH with Control Master 2013-06-27 Selenium, xvfb and Jenkins sidunea 2013-06-27 Automatic login with ssh 2013-06-27 JBehave - for whom? 2013-06-26 Categories Gradle JBehave Jenkins Performance Test Automation Versioning
No comments:
Post a Comment