詹金斯:是否可以使用Jenkinsfile创建常春藤作业? (管道代码)

时间:2016-06-28 19:33:31

标签: jenkins ivy jenkins-pipeline

我有几个使用Ivy的项目,因此我创建了Ivy作业,用于构建和发布我的工件到存储库。

Ivy插件非常有用,因为它以自动方式处理我的依赖关系。但是,我正在将这些工作转移到"管道中作为代码"方法,并希望使用//REFERENCE DLL public OdbcDataReader RawQuery(string query_to_perform) { // This method executes a query in the specific database that you // are connected to. System.Data.Odbc.OdbcCommand command = null; // holds the query sent to the database System.Data.Odbc.OdbcDataReader result_reader = null; // The query is put into an OdbcCommand object and sent to the database. The // return result will then be given back to the caller. try { if (loggingEnabled) { myLog = File.AppendText(loggingFileName); myLog.WriteLine(query_to_perform); myLog.Close(); myLog.Dispose(); } command = new System.Data.Odbc.OdbcCommand(query_to_perform, this.database_connection); result_reader = command.ExecuteReader(); this.successful_query = true; this.error_message = ""; } catch (System.Data.Odbc.OdbcException ex) { this.successful_query = false; this.error_message = ex.Message; //destroy the connection on a failure database_connection = new OdbcConnection(); throw; } return result_reader; } 来自动为我的每个项目创建作业。

我的疑问是:我可以使用Jenkinsfile创建相同的工作(常春藤)吗?如果没有,我可以使用Jenkinsfile创建任何类型的常春藤作业吗?

1 个答案:

答案 0 :(得分:2)

您可以使用Jenkins文件中的Job DSL插件创建新作业,请参阅https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#use-job-dsl-in-pipeline-scripts

以下管道代码调用Job DSL构建步骤,然后运行ivyJob.groovy Job DSL脚本。

node {
  step([
    $class: 'ExecuteDslScripts',
    scriptLocation: [targets: ['ivyJob.groovy']],
    removedJobAction: 'DELETE',
    removedViewAction: 'DELETE',
    lookupStrategy: 'SEED_JOB',
  ])
}

ivyJob.groovy脚本将创建一个Ivy作业并运行Ant构建:

ivyJob('example') {
  ivyBuilder {
    ant {
      target('clean')
      targets(['test', 'publish'])
      buildFile('build.xml')
      antInstallation('Ant 1.9')
      prop('key', 'value')
      javaOpt('-Xmx=1G')
    }
  }
}

有关详细信息,请参阅Job DSL API文档: https://jenkinsci.github.io/job-dsl-plugin/#path/ivyJob