Can't use variable to set bool fields

Bug #1335945 reported by Ryan Carey
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Core Infrastructure
Fix Committed
Undecided
Khai Do

Bug Description

Trying to set bool field in a job-template using a variable doesn't work. This is caused by a combination of limitations:

1. brackets for a variable reference need to be enclosed in single-quotes or the variable ref will be mis-interrupted by the YAML parser as a YAML dictionary. '{var_ref}' not {var_ref}

2. With the single quotes around the variable reference the value is converted to a string. For the specific boolean fields (disabled, block-downstream, block-upstream), any string value results in a boolean value true. The values '', 'true', 'false' all result in a true value in the geneted XML.

Boolean fields should be able to accept string values such as 'true' or 'False'. The following is a snippet of YAML to demonstrate the problem:

- job-template:
    name: 'test_project'
    disabled: '{disabled}'

-project:
    name: test_project
    jobs:
      - 'test_job':
          disabled: true

The problem can be traced to the file jenkins_jobs/modules/general.py, and occurs for the following fields:

disabled
block-downstream
block-upstream

Tags: jjb
Revision history for this message
Ryan Carey (rcarey) wrote :
tags: added: jjb
Ryan Carey (rcarey)
Changed in openstack-ci:
assignee: nobody → Ryan Carey (rcarey)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to jenkins-job-builder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/104294

Changed in openstack-ci:
status: New → In Progress
Revision history for this message
Darragh Bailey (dbailey-k) wrote :

This was fixed by: https://review.openstack.org/#/c/73990

The problem is that the bool data type is getting converted to a string because it was being inserted via the string format method. https://review.openstack.org/#/c/73990 added the capability to use parameter retrieval by key name which retains the original object type for cases where the substitution needs to be handled differently.

The trick is that you have to use '{obj:disabled}' in the template to trigger this behaviour with JJB.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on jenkins-job-builder (master)

Change abandoned by Ryan Carey (<email address hidden>) on branch: master
Review: https://review.openstack.org/104294
Reason: Tested Darragh Bailey's comment. This change is not necessary. Undocumented feature '{obj:disabled}' solves the problem of passing booleans to job-templates.

Khai Do (zaro0508)
Changed in openstack-ci:
status: In Progress → Invalid
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to jenkins-job-builder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/130391

Changed in openstack-ci:
assignee: Ryan Carey (rcarey) → Khai Do (zaro0508)
status: Invalid → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to jenkins-job-builder (master)

Reviewed: https://review.openstack.org/130391
Committed: https://git.openstack.org/cgit/openstack-infra/jenkins-job-builder/commit/?id=ec94d26386a4514e46d95f5b187e9fbf2b91af81
Submitter: Jenkins
Branch: master

commit ec94d26386a4514e46d95f5b187e9fbf2b91af81
Author: Khai Do <email address hidden>
Date: Wed Oct 22 16:17:28 2014 -0700

    Add additional documentation for passing objects to templates

    I noticed that users were not really aware of how this feature
    worked so added additional documentation for it.

    Change-Id: Ic5385ae859295cdd015d698ede3da4988efd9ca7
    Closes-Bug: 1335945

Changed in openstack-ci:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.