Many Freestyle jobs or many Jenkinsfiles?

62 views
Skip to first unread message

Al Silver

unread,
Jun 1, 2020, 11:37:46 AM6/1/20
to Jenkins Users
I've used Jenkins a little but not in the traditional method of CI/CD. I'm using Jenkins as a Web UI to run individual python scripts for networking devices... Users would log into Jenkins and then select any one of numerous Freestyle projects (with parameters) to run (there could be 100 or more...).    The job executes a shell which runs a pytest script that logs into (via ssh) multiple networking devices and performs some actions... pretty straightforward and it works ok but has some limitations.  With that said, I think I'll have more flexibility and power building and maintaining these jobs as pipelines and treating them as code.  My question is I guess I would need to convert my pipelines into Jenkinsfiles?  However, most of the docs I read show a single Jenkinsfile (named "Jenkinsfile") I would need one for each job (a 100 or so).  I must be missing something here or not understanding.  Can someone point in the right direction for what I'm trying to accomplish?

Thx
Al

Anatoly Utkin

unread,
Jun 1, 2020, 2:18:16 PM6/1/20
to Jenkins Users
You can, of course, configure a pipeline and use any groovy file that you check out from SCM, Jenkinsfile is the general name of that file, and in some cases default, but see here n.5:

Anatoly.

Randy Beckwith

unread,
Jun 2, 2020, 7:24:38 AM6/2/20
to jenkins...@googlegroups.com

As far as I know, “Jenkinsfile” is just a naming convention. I have multiple Jenkins files:

 

JenkinsFile.Parallel.groovy

JenkinsFile.Parallel.Snapshot.groovy

JenkinsFile.PatchWeekend-VmManager.groovy

 

I also add the .groovy extension so that editors can do syntax highlighting.

 

Randy

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/64f8998b-67f2-48ba-a0fa-6cdbdd4113ab%40googlegroups.com.

Giles

unread,
Jun 2, 2020, 3:58:27 PM6/2/20
to Jenkins Users
I wrote a large library file full of Groovy methods.  I have a big stack of Jenkinsfiles, similar to Randy Beckworth, although mine are generally named "<purpose>/<environment>.Jenkinsfile" (as you can see, Jenkins isn't very particular about naming).  The Jenkinsfiles are generally very short, just long enough to call one of the library methods with a set of parameters.  We have 50-80 Jenkins jobs, and each of those has its own Jenkins file.  The initial set-up was tedious, but now that it's all in place it works very well.  Not sure if you could call a Python library, or if you'll end up using Groovy to call Python scripts.  My Groovy calls a lot of shell scripts - it's ugly, but works surprisingly well so you can make that work if you have to.

I think there are plugins and/or programmatic methods of generating jobs to avoid doing a lot of that tedious work yourself, but I also think you'd have to be looking at a very big setup (thousands of jobs) before it would be worth the investment of time to understand those plugins/methods.

Learning Jenkins' version of Groovy is a bit of a trip: it has a lot of its own methods, and I've found some weird edge cases where Jenkins' Groovy doesn't behave the same as standard Groovy.  All that said - it's definitely been worth the work.

monger_39

unread,
Jun 4, 2020, 7:01:15 AM6/4/20
to Jenkins Users
similar to other users I also have a quite large set of jobs that use the (scripted, not declarative) Groovy pipelines. In my setup I have deliberately chosen to:
  • store all the Groovy scripts in SCM
  • have a seperate dedicated repository for all my Groovy scripts;
    alternative would be to store the JenkinsFile in the same repo as where the test data is stored.
  • use groovy 'load' to pull in generic utility code.
    alternative is using shared libraries; I prefer local load since it allows me to use SCM branches of my jenkins repository

I also started from historic Freestyle jobs. First thing I did is transform the Freestyle job into one that calls a single script with parameters from a repo.
Then create a very simple pipeline job that call that very script. Then slowly start taking more parts of the script into the groovy code.
For me doing it big-bang was a no-go. Have been hit by the Groovy diffs similar to what @Giles also mentioned. Take small steps. Debugging Groovy
in Jenkins is extremely hard. Investigate the use of "Replay" !
Once you have the first job running, the rest will be much easier.
good luck.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit

Jérôme Godbout

unread,
Jun 4, 2020, 9:27:35 AM6/4/20
to jenkins...@googlegroups.com

Nearly the same here:

  1. Common code into one repos
  2. Jenkinsfile for each project into his own repos
  3. Source into his own repos

 

When I run, I can checkout the proper jenkinsfile (branch, version) from the repos #2. It will checkout his needed version of the toolings repos #1. Then it will checkout the related source code and start building/testing, etc.

 

This split the way we do the build from the source code, the source code is totally agnostic of the build system. I can have different build script for different system. I can versionize my tools to get the same results every times. The slave doesn’t need anything installed, so the Jenkins only need the required plugins and credentials and tons of scripts approvals upon install.

 

 

From: 'monger_39' via Jenkins Users <jenkins...@googlegroups.com>

Sent: June 4, 2020 7:01 AM
To: Jenkins Users <jenkins...@googlegroups.com>

Al Silver

unread,
Jun 12, 2020, 11:29:52 AM6/12/20
to Jenkins Users
Thanks for all of the ideas.  For now, I created a jenkins directory in my pytest root directory (basically the root directory of the project).  I then created name specific directories under there for organization.  Under those directories, there are multiple jenkinsfiles (not named jenkinsFile).  The pipeline files call a python script which processes all of the parameters and then generates a command line.  The entire command line is stored as a variable and then run through the shell.  Glad I got it working and seems ok for now.  One thing I don't really like about the workflow is for each pipeline job that is created, I still have to first create the job using the GUI and then I need to manually enter the "Script Path" to point to the appropriate pipeline file.  Is there anyway to create the entire Jenkins Job in code so that when the Jenkins GUI is opened up, the new jobs "magically" appear?

monger_39

unread,
Jun 16, 2020, 2:52:22 AM6/16/20
to jenkins...@googlegroups.com
check Jenkins Configuration as Code

After installing the plugin, use the export to generate a 'representative' piece of code for the type of jobs 
you want to use. Then you could run some script to generate a new JCASC file with similar jobs, and 
import that. I personally find the exact syntax of the JCASC yaml files still hard to hand-write, but for
simple jobs like running a pipeline from SCM it's quite easy.




--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages