How to access Groovy file from Jenkins Seed Job using DSL - jenkins

Create Jenkins Seed Job using DSL Plugin - Where i can pass Git Repo location to create the Jenkins jobs for the repo. The Job is created programmatically in the repo. Seed Job should read the groovy file in the repo and create the new job.

You can :
Checkout Groovy file from Seed Job
Access file programmatically from code of Seed Job (some SCM tools provide API, ie. Bitbucket, github)

Related

Is it possible to update Jenkins parametrized scheduler configuration using API?

I want to keep Jenkins parametrized scheduler configuration in a file in git.
It would be very convenient if there is a way to update a job parametrized scheduler configuration via a custom script which reads the config file from repo and post it to the job.
Is there such functionality in Jenkins API?

How to let the Job DSL plugin fetch all jobs from remote Git instead of local file system?

I would like to set up many jobs automatically. In the build step "Process Job DSLs", the job-dsl plugin allows to either "Use the provided DSL script" or "Look on Filesystem" for doing its thing. While "Look on Filesystem" looks like what I'm looking for, since it allows to define multiple Job DSL files at once, it sources them from a directory on the Jenkins server. I would rather have it fetch those job specifications from a remote Git repository.
Therefore, is it possible to source all jobs from a remote Git repository? Somehow like this pseudo code?

point to Git repository as source for Jenkins Job DSL job?

I have the option of file system or embedded script - how can I point to a Git repo?
I am asking specifically about the Job DSL not Multibranch Pipelines.
Just add a standard SCM step to your job configuration. In that step, check out the needed repository and branch that contains the DSL script.
The "DSL Scripts" argument then has to point to the script that you checked out in that step.
I don't think you can point it to a git repo using the Process Job DSLs build step. Instead if you use Job DSL in a pipeline script as described here you can check out the repo first on to your job workspace and use the DSL script as target in your jobDsl build step

Is it possible to run a Seed Job without publishing the generated jobs?

Apache Beam uses the Jenkins Job DSL plugin with a seed job responsible for generating the rest of our Jenkins jobs from groovy source files (sample run).
The job definitions are authored as Groovy scripts and maintained in source control just like other source code. I would like to more easily verify changes to Jenkins job definitions during code review.
We already have the ability to run our Seed Job on a GitHub pull request, however the updated jobs get published right away and replace the existing jobs. Is it possible to run a Seed Job on Jenkins but not publish the generated job? Ideally it would run the Seed Job script and output the generated XML somewhere without actually committing it to Jenkins. Perhaps it could even show a diff against the existing job definition.

Jenkins change log when using multiple repositories

We are using Jenkins pipeline for job executions and pipeline code is committed to subversion repository and checkout as Jenkins library. So whenever I execute job, it will look for changes at my pipeline code repository and publish the change logs. Changes committed to application source code repository is ignoring because of this reason. Do we have any options to specify which repository change logs should be published at Jenkins?

Resources