title: Programmatically creating jenkins pipeline jobs with xml
body: <p>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).</p>
  
  <p>I have a pipleine config:</p>
  
  <pre><code>&lt;flow-definition plugin="workflow-job@2.4"&gt;
  &lt;actions/&gt;
  &lt;description/&gt;
  &lt;keepDependencies&gt;false&lt;/keepDependencies&gt;
  &lt;properties&gt;
      &lt;org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty&gt;
          &lt;triggers/&gt;
      &lt;/org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty&gt;
      &lt;com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.20.0"&gt;
          &lt;projectUrl&gt;https://github.xxx.net/djin-infrastructure/terraform-test.git/&lt;/projectUrl&gt;
          &lt;displayName/&gt;
      &lt;/com.coravy.hudson.plugins.github.GithubProjectProperty&gt;
      &lt;com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty plugin="ownership@0.8"/&gt;
      &lt;com.suryagaddipati.jenkins.SlaveUtilizationProperty plugin="slave-utilization-plugin@1.8"&gt;
          &lt;needsExclusiveAccessToNode&gt;false&lt;/needsExclusiveAccessToNode&gt;
          &lt;singleInstancePerSlave&gt;false&lt;/singleInstancePerSlave&gt;
          &lt;slaveUtilizationPercentage&gt;0&lt;/slaveUtilizationPercentage&gt;
      &lt;/com.suryagaddipati.jenkins.SlaveUtilizationProperty&gt;
      &lt;hudson.model.ParametersDefinitionProperty&gt;
          &lt;parameterDefinitions&gt;
              &lt;hudson.model.ChoiceParameterDefinition&gt;
                  &lt;name&gt;environment&lt;/name&gt;
                  &lt;description&gt;
                      &lt;p&gt;&lt;b&gt;These should match the folders within your root of workspace.&lt;/b&gt;&lt;/p&gt;
                  &lt;/description&gt;
                  &lt;choices class="java.util.Arrays$ArrayList"&gt;
                      &lt;a class="string-array"&gt;
                          &lt;string&gt;dev&lt;/string&gt;
                          &lt;string&gt;int&lt;/string&gt;
                          &lt;string&gt;stag&lt;/string&gt;
                          &lt;string&gt;prod&lt;/string&gt;
                      &lt;/a&gt;
                  &lt;/choices&gt;
              &lt;/hudson.model.ChoiceParameterDefinition&gt;
              &lt;hudson.model.StringParameterDefinition&gt;
                  &lt;name&gt;slackChannelName&lt;/name&gt;
                  &lt;description&gt;
                      &lt;p&gt;&lt;b&gt;Slack channel name that needs to be notified on infrastructure changes.&lt;/b&gt;&lt;/p&gt;
                  &lt;/description&gt;
                  &lt;defaultValue&gt;defaultslack&lt;/defaultValue&gt;
              &lt;/hudson.model.StringParameterDefinition&gt;
              &lt;hudson.model.ChoiceParameterDefinition&gt;
                  &lt;name&gt;action&lt;/name&gt;
                  &lt;description&gt;
                      &lt;p&gt;&lt;b&gt;apply - create/update infrastructure; destroy - destroy infrastructure.&lt;/b&gt;&lt;/p&gt;
                  &lt;/description&gt;
                  &lt;choices class="java.util.Arrays$ArrayList"&gt;
                      &lt;a class="string-array"&gt;
                          &lt;string&gt;apply&lt;/string&gt;
                          &lt;string&gt;destroy&lt;/string&gt;
                      &lt;/a&gt;
                  &lt;/choices&gt;
              &lt;/hudson.model.ChoiceParameterDefinition&gt;
              &lt;hudson.model.ChoiceParameterDefinition&gt;
                  &lt;name&gt;githubUrl&lt;/name&gt;
                  &lt;description&gt;
                      &lt;p&gt;&lt;b&gt;This is the github url for your terraform scripts.&lt;/b&gt;&lt;/p&gt;
                  &lt;/description&gt;
                  &lt;choices class="java.util.Arrays$ArrayList"&gt;
                      &lt;a class="string-array"&gt;
                          &lt;string&gt;defaultgithub&lt;/string&gt;
                      &lt;/a&gt;
                  &lt;/choices&gt;
              &lt;/hudson.model.ChoiceParameterDefinition&gt;
          &lt;/parameterDefinitions&gt;
      &lt;/hudson.model.ParametersDefinitionProperty&gt;
  &lt;/properties&gt;
  &lt;definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.10"&gt;
      &lt;scm class="hudson.plugins.git.GitSCM" plugin="git@2.5.2"&gt;
          &lt;configVersion&gt;2&lt;/configVersion&gt;
          &lt;userRemoteConfigs&gt;
              &lt;hudson.plugins.git.UserRemoteConfig&gt;
                  &lt;url&gt;https://github.xxx.net/kaulk/improveD.git&lt;/url&gt;
              &lt;/hudson.plugins.git.UserRemoteConfig&gt;
          &lt;/userRemoteConfigs&gt;
          &lt;branches&gt;
              &lt;hudson.plugins.git.BranchSpec&gt;
                  &lt;name&gt;*/master&lt;/name&gt;
              &lt;/hudson.plugins.git.BranchSpec&gt;
          &lt;/branches&gt;
          &lt;doGenerateSubmoduleConfigurations&gt;false&lt;/doGenerateSubmoduleConfigurations&gt;
          &lt;gitTool&gt;Default&lt;/gitTool&gt;
          &lt;submoduleCfg class="list"/&gt;
          &lt;extensions/&gt;
      &lt;/scm&gt;
      &lt;scriptPath&gt;Jenkinsfile&lt;/scriptPath&gt;
  &lt;/definition&gt;
  &lt;triggers/&gt;
  </code></pre>
  
  <p></p>
  
  <p>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:</p>
  
  <p>this is when I build it :</p>
  
  <p><a href="https://i.stack.imgur.com/Y9QQ7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y9QQ7.png" alt="Notice the stages and job succeeding"></a></p>
  
  <p>As the job finishes and succeeds this what the UI ends up with :</p>
  
  <p><a href="https://i.stack.imgur.com/q0XFi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q0XFi.png" alt="Notice 4th build is green but the UI shows failure and all stages are gone. "></a></p>
  
  <p>I dont see anything unique in the config.xml that might be messing things up. Has anyone tried this or any ideas?</p>