Jenkins job-dsl生成的作业缺少SCM

时间:2017-10-11 23:18:23

标签: jenkins groovy jenkins-job-dsl

我有创建Jenkins工作的种子工作,在创建工作时,他们会遗漏SCM,标签和包装器等内容。

这是一个简单的创建作业脚本:

job(jobName) {
  label('pdfs')
  description jobDesc
  parameters {
    textParam('PDF_BRANCH', 'release/server_2.11.1', '')
  }
  scm {
    git {
      remote {
        url('https://stash.domain.com/scm/project/repo.git')
        credentials('repo-user-creds')
      }
      branch('*/master')
    }
  }
  triggers {
    scm 'H/5 * * * *'
  }
  steps {
    shell jobScript
  }
  wrappers {
    rbenv('1.9.3-p484') {
      ignoreLocalVersion()
      gems('bundler', 'rake')
    }
  }
}

但是生成的作业没有SCM或标签: enter image description here 服务器上的XML似乎包含SCM和标签:

<?xml version="1.0" encoding="UTF-8"?><project>
    <actions/>
    <description>Testing pdf creation job against Elemental Server</description>
    <keepDependencies>false</keepDependencies>
    <properties>
        <hudson.model.ParametersDefinitionProperty>
            <parameterDefinitions>
                <hudson.model.TextParameterDefinition>
                    <name>PDF_BRANCH</name>
                    <defaultValue>release/server_2.11.1</defaultValue>
                    <description/>
                </hudson.model.TextParameterDefinition>
            </parameterDefinitions>
        </hudson.model.ParametersDefinitionProperty>
    </properties>
    <canRoam>false</canRoam>
    <disabled>false</disabled>
    <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
    <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
    <triggers>
        <hudson.triggers.SCMTrigger>
            <spec>H/5 * * * *</spec>
            <ignorePostCommitHooks>false</ignorePostCommitHooks>
        </hudson.triggers.SCMTrigger>
    </triggers>
    <concurrentBuild>false</concurrentBuild>
    <builders>
        <hudson.tasks.Shell>
            <command>
# REMOVED FOR BREVITY
</command>
        </hudson.tasks.Shell>
    </builders>
    <publishers/>
    <buildWrappers>
        <ruby-proxy-object>
            <ruby-object ruby-class="Jenkins::Tasks::BuildWrapperProxy" pluginid="rbenv">
                <pluginid ruby-class="String" pluginid="rbenv">rbenv</pluginid>
                <object ruby-class="RbenvWrapper" pluginid="rbenv">
                    <version ruby-class="String" pluginid="rbenv">1.9.3-p484</version>
                    <ignore__local__version ruby-class="String" pluginid="rbenv">true</ignore__local__version>
                    <gem__list ruby-class="String" pluginid="rbenv">bundler,rake</gem__list>
                    <rbenv__root ruby-class="String" pluginid="rbenv">$HOME/.rbenv</rbenv__root>
                    <rbenv__repository ruby-class="String" pluginid="rbenv">https://github.com/sstephenson/rbenv.git</rbenv__repository>
                    <rbenv__revision ruby-class="String" pluginid="rbenv">master</rbenv__revision>
                    <ruby__build__repository ruby-class="String" pluginid="rbenv">https://github.com/sstephenson/ruby-build.git</ruby__build__repository>
                    <ruby__build__revision ruby-class="String" pluginid="rbenv">master</ruby__build__revision>
                </object>
            </ruby-object>
        </ruby-proxy-object>
    </buildWrappers>
    <assignedNode>pdfs</assignedNode>
    <scm class="hudson.plugins.git.GitSCM">
        <userRemoteConfigs>
            <hudson.plugins.git.UserRemoteConfig>
                <url>https://stash.domain.com/scm/project/repo.git</url>
                <credentialsId>repo-user-creds</credentialsId>
            </hudson.plugins.git.UserRemoteConfig>
        </userRemoteConfigs>
        <branches>
            <hudson.plugins.git.BranchSpec>
                <name>*/master</name>
            </hudson.plugins.git.BranchSpec>
        </branches>
        <configVersion>2</configVersion>
        <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
        <gitTool>Default</gitTool>
    </scm>

我对詹金斯的工作非常新,所以我确定我错过了一些相当明显的东西,但我不知道它是什么。非常感谢任何帮助,谢谢!

2 个答案:

答案 0 :(得分:0)

查找Jenkins日志中的任何错误并尝试重新启动Jenkins。

Job DSL维基中有一个相关的FAQ条目: https://github.com/jenkinsci/job-dsl-plugin/wiki/Frequently-Asked-Questions#why-isnt-my-generated-job-like-i-was-expecting-there-was-no-error-when-the-seed-job-ran

答案 1 :(得分:0)

尝试在此验证您的代码 job DSL playground

如果所有标签都很好,那么您可能需要检查DSL插件版本以及DSL方法的任何更新