jenkins-docs / quickstart-tutorials

Jenkins tutorial files
MIT License
10 stars 179 forks source link

Add profile specific jobs #409

Open uhafner opened 2 months ago

uhafner commented 2 months ago

The current setup creates a running configuration of Jenkins with a specific agent, e.g. a maven agent. It would be also helpful, if the provided hello-world job would be profile dependent. I.e., when selecting the maven profile it should configure and build a maven project, and so on.

In my Jenkins student setup I am using such jobs for maven, see https://github.com/uhafner/codingstyle/tree/main/docker/images/jenkins-controller/preconfigured-jobs for more details.

Since I did not find an easy way to add profile specific jobs here, I created this issue rather than a PR. Once the general idea is possible, I can copy one of my projects of my codingstyle into this tutorial repository.

gounthar commented 2 months ago

Thanks a lot for this proposal, Ulli. I'll have a look at your repo.

gounthar commented 2 months ago

Adding Jobs to the Controller Image

Current Setup

The jobs supplied with the current controller image are defined in the jobs subdirectory of the dockerfiles directory.

Potential for Expansion

Adding other jobs to the controller image is technically feasible and relatively straightforward.

Challenges and Considerations

The main challenge lies in tailoring the job list for each profile:

Possible Solutions

We have two main approaches to consider:

  1. API-based Job Management:

    • Use the API at the start of the controller to adjust the job list
    • This method would involve removing irrelevant jobs for each profile
  2. Post-Start Job Addition:

    • Add specific jobs per profile after the Jenkins controller has started
    • This approach would involve adding only the relevant jobs for each profile

Both solutions have their merits and drawbacks, warranting further discussion and evaluation.

uhafner commented 2 months ago

Wouldn't it be simpler if we would create for each profile that contains specific jobs another Docker compose service, that simply copies the specific job into a volume? And then the controller can copy these files into the job folder? Like the sidekick image is using the ssh folder? Or is this not possible in Docker?

gounthar commented 2 months ago

I have a PoC that works with the maven profile for the time being, but it's still failing with the python profile. It's promising, though, and it uses the existing docker services.