Add example for variable expansion inside macros and jobs

Story: 2010588
Story: 2010963
Change-Id: Ifb51b267db3b32f380d571ce4bc71cb9662f895c
This commit is contained in:
Vsevolod Fedorov 2023-11-13 10:50:23 +03:00
parent 35a75d28e5
commit 081fcaa0d3
6 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<displayName>sample-job</displayName>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<displayName>sample-job-template</displayName>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should be expanded: sample param value
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should be expanded: sample param value
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should be expanded: sample param value
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should not be expanded: {param}
</command>
</hudson.tasks.Shell>
<hudson.tasks.Shell>
<command>echo Should be expanded: sample param value
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,51 @@
# Example for tickets:
# https://storyboard.openstack.org/#!/story/2010588 Expand macros even if called without arguments
# https://storyboard.openstack.org/#!/story/2010963 Expand jobs the same way as job templates are expanded
# Demonstrate different style of variable expansion and inclusion tags for
# macros with and without parameters and for jobs versus job templates.
- builder:
name: builder-without-params
builders:
- shell: |
echo Should not be expanded: {param}
- shell: !include-raw: job-and-macro-expansions.yaml.no-expand.inc
- builder:
name: builder-with-params
builders:
- shell: |
echo Should not be expanded: {{param}}
- shell: |
echo Should be expanded: {param}
- shell: !include-raw-escape: job-and-macro-expansions.yaml.no-expand.inc
- shell: !include-raw: job-and-macro-expansions.yaml.expand.inc
- job:
name: sample-job
display-name: sample-job
builders:
- shell: |
echo Should not be expanded: {param}
- shell: !include-raw: job-and-macro-expansions.yaml.no-expand.inc
- job-template:
name: sample-job-template
display-name: sample-job-template
builders:
- builder-without-params
- builder-with-params:
param: sample param value
- shell: |
echo Should not be expanded: {{param}}
- shell: |
echo Should be expanded: {param}
- shell: !include-raw-escape: job-and-macro-expansions.yaml.no-expand.inc
- shell: !include-raw: job-and-macro-expansions.yaml.expand.inc
- project:
name: sample-project
param: sample param value
jobs:
- sample-job-template

View File

@ -0,0 +1 @@
echo Should be expanded: {param}

View File

@ -0,0 +1 @@
echo Should not be expanded: {param}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders>
<hudson.tasks.Shell>
<command>echo Build arch {arch}.</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,10 @@
# Variables in jobs are not expanded.
- defaults:
name: global
arch: 'i386'
- job:
name: sample-job
builders:
- shell: "echo Build arch {arch}."