Re: [jjb] creating jobname with input parameter in JJB

34 views
Skip to first unread message
Message has been deleted

Vsevolod Fedorov

unread,
Sep 28, 2023, 7:26:25 AM9/28/23
to Suman Meesala, jenkins-job-builder

=========

$ jenkins-jobs update --help

usage: jenkins-jobs update [-h] [-r] [-x EXCLUDE] [--delete-old] [-p PLUGINS_INFO_PATH] [--workers N_WORKERS] [--existing-only] [--enabled-only] [-j | -v]
                           [path] [names ...]
=========

Looks like your parameter, env=SAM is treated as job name that should be selected. But code sample you provided does not generate job with such a name, but only job named `$env_$jobname`.

JJB does not support variable expansion from environment variables.


Vsevolod.

On 9/28/23 13:49, Suman Meesala wrote:
Hi everyone,

I want to create a job in JJB with name {env}_job...
Here I want to give env as input paramter.

============================================
- view-template:
    name: '{env}_lstview'
    description: 'My View Description'
    view-type: list
    regex: '{env}_.*'  # Include all jobs

- job-template:
    name: '{env}_{jobname}'
    parameters:
      - string:
          name: env
          default: DEF
      - string:
          name: jobname
          default: sampl_job
    customerName: customerName
    description: "Jenkins Job Template with Custom Configuration"
    builders:
      - shell: 'ls'

- project:
    name: CC
    views:
      - '{env}_lstview':
          env: $env
    jobs:
      - '{env}_{jobname}':
          env: $env
          jobname: $jobname
==============================

jenkins_jobs]# jenkins-jobs --conf jenkins_jobs update sampjobs env=SAM
WARNING:jenkins_jobs.config:Config file, jenkins_jobs, not found. Using default config values.
INFO:jenkins_jobs.config:Will use anonymous access to Jenkins if needed.
INFO:jenkins_jobs.cli.subcommand.base:Updating jobs in [PosixPath('sampjobs')] (['env=SAM'])
INFO:jenkins_jobs.builder:Number of jobs generated:  0
INFO:jenkins_jobs.cli.subcommand.update:Number of jobs updated: 0
INFO:jenkins_jobs.builder:Number of views generated:  0
INFO:jenkins_jobs.cli.subcommand.update:Number of views updated: 0

but no job is getting generated.

Please help me resolve this issue.

Thanks,
--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkins-job-builder/7426dd07-b5c3-4160-9f1d-0748797c3362n%40googlegroups.com.
Message has been deleted

Vsevolod Fedorov

unread,
Sep 28, 2023, 7:44:07 AM9/28/23
to Suman Meesala, jenkins-job-builder

Hi, Suman.

You can use several approaches for this.

  1. You create project(s) that lists all your jobs, for all environments. Add environment name to names of your jobs, for example, as prefix. Like dev.my-job, stage.my-job etc.
    Then, you specify that prefix when you update your jobs. Like: jenkins-jobs update my-jobs-dir 'stage.*'.
  2. Alternatively, you can create separate files or folders for each of environment and one folder or file for common templates. Put all templates to common and instantiate then from projects in specific environment.
    Like: jenkins-jobs update prod-dir,common-dir.


Vsevolod.

On 9/28/23 14:33, Suman Meesala wrote:

Thank you for the reply,

Actually I have some 50 jobs to be created in different environments like DEV, STG, PRD.
So that is the reason im using env_jobname, but here evertime i cannot change env to DEV or PRD, because the jobs list may increase...
Is there any alternative to acheive this?
Reply all
Reply to author
Forward
0 new messages