Programmatically creating jenkins pipeline jobs with xml

时间:2016-08-31 17:47:01

标签: xml jenkins groovy jenkins-plugins jenkins-pipeline

I have a pipeline job xml that I am using to create other similar pipeline job using a shell job. (I've done this before with before 2.0 and they worked).

I have a pipleine config:

<flow-definition plugin="workflow-job@2.4">
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
    <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
        <triggers/>
    </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
    <com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.20.0">
        <projectUrl>https://github.xxx.net/djin-infrastructure/terraform-test.git/</projectUrl>
        <displayName/>
    </com.coravy.hudson.plugins.github.GithubProjectProperty>
    <com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty plugin="ownership@0.8"/>
    <com.suryagaddipati.jenkins.SlaveUtilizationProperty plugin="slave-utilization-plugin@1.8">
        <needsExclusiveAccessToNode>false</needsExclusiveAccessToNode>
        <singleInstancePerSlave>false</singleInstancePerSlave>
        <slaveUtilizationPercentage>0</slaveUtilizationPercentage>
    </com.suryagaddipati.jenkins.SlaveUtilizationProperty>
    <hudson.model.ParametersDefinitionProperty>
        <parameterDefinitions>
            <hudson.model.ChoiceParameterDefinition>
                <name>environment</name>
                <description>
                    <p><b>These should match the folders within your root of workspace.</b></p>
                </description>
                <choices class="java.util.Arrays$ArrayList">
                    <a class="string-array">
                        <string>dev</string>
                        <string>int</string>
                        <string>stag</string>
                        <string>prod</string>
                    </a>
                </choices>
            </hudson.model.ChoiceParameterDefinition>
            <hudson.model.StringParameterDefinition>
                <name>slackChannelName</name>
                <description>
                    <p><b>Slack channel name that needs to be notified on infrastructure changes.</b></p>
                </description>
                <defaultValue>defaultslack</defaultValue>
            </hudson.model.StringParameterDefinition>
            <hudson.model.ChoiceParameterDefinition>
                <name>action</name>
                <description>
                    <p><b>apply - create/update infrastructure; destroy - destroy infrastructure.</b></p>
                </description>
                <choices class="java.util.Arrays$ArrayList">
                    <a class="string-array">
                        <string>apply</string>
                        <string>destroy</string>
                    </a>
                </choices>
            </hudson.model.ChoiceParameterDefinition>
            <hudson.model.ChoiceParameterDefinition>
                <name>githubUrl</name>
                <description>
                    <p><b>This is the github url for your terraform scripts.</b></p>
                </description>
                <choices class="java.util.Arrays$ArrayList">
                    <a class="string-array">
                        <string>defaultgithub</string>
                    </a>
                </choices>
            </hudson.model.ChoiceParameterDefinition>
        </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.10">
    <scm class="hudson.plugins.git.GitSCM" plugin="git@2.5.2">
        <configVersion>2</configVersion>
        <userRemoteConfigs>
            <hudson.plugins.git.UserRemoteConfig>
                <url>https://github.xxx.net/kaulk/improveD.git</url>
            </hudson.plugins.git.UserRemoteConfig>
        </userRemoteConfigs>
        <branches>
            <hudson.plugins.git.BranchSpec>
                <name>*/master</name>
            </hudson.plugins.git.BranchSpec>
        </branches>
        <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
        <gitTool>Default</gitTool>
        <submoduleCfg class="list"/>
        <extensions/>
    </scm>
    <scriptPath>Jenkinsfile</scriptPath>
</definition>
<triggers/>

I have a shell file that uses the config to create there pipeline jobs. IT gets created fine and when I run it works fien and succeeds but the UI for pipeline gets screwed:

this is when I build it :

Notice the stages and job succeeding

As the job finishes and succeeds this what the UI ends up with :

Notice 4th build is green but the UI shows failure and all stages are gone.

I dont see anything unique in the config.xml that might be messing things up. Has anyone tried this or any ideas?

0 个答案:

没有答案