简体   繁体   English

Jenkins 到 Bamboo 迁移和运行 Groovy

[英]Jenkins to Bamboo Migration & Running Groovy

I'm fairly new to Jenkins and a total newbie to Bamboo.我对 Jenkins 和 Bamboo 完全是新手。 I have a Jenkins Pipeline and I'm trying to create an equivalent in Bamboo (I believe it's called a Plan).我有一个 Jenkins 管道,我正在尝试在 Bamboo 中创建一个等价物(我相信它被称为计划)。

I've got some groovy code that I want to run in my Bamboo plan.我有一些 groovy 代码要在我的 Bamboo 计划中运行。

I'll simplify the code below for brevity and clarity.为了简洁明了,我将简化下面的代码。

Assume this file is called me_myEvent.groovy and is stored at https://github.com/myuser/repo1假设此文件名为me_myEvent.groovy并存储在https://github.com/myuser/repo1

def processEvent( Map args ) {
  String strArg1 = args.myArg1;
  String strArg2 = args.myArg2;
  // etc...
}

My Jenkins pipeline has a global pipeline library ( myGitLibraryFromGlobal ) linking to https://github.com/myuser/repo1 and my pipeline is:我的 Jenkins 管道有一个全局管道库( myGitLibraryFromGlobal )链接到https://github.com/myuser/repo1我的管道是:

@Library('myGitLibraryFromGlobal@master') abc

pipeline {
  agent any
  stages {    
    stage('First Stage') {
      steps {
          script {
            def myObj = new com.mysite.me_myEvent();
            def returnVal = myObj.processEvent(arg1: 'foo', arg2: 'bar');
          }
      }
    })
  }
}

I've got the GitHub repo saved in Bamboo as a global linked repository called abc123 .我将 GitHub 存储库保存在 Bamboo 中,作为名为abc123的全局链接存储库。

Can I achieve the same thing in Bamboo using the script task?我可以使用script任务在 Bamboo 中实现相同的功能吗? What would this look like in Bamboo?这在 Bamboo 中会是什么样子?

The short answer is NO , as Atlassian Bamboo doesn't support the DSL Groovy or Scripted Groovy pipeline .简短的回答是NO ,因为 Atlassian Bamboo 不支持DSL Groovy 或 Scripted Groovy 管道 Also, please keep in mind that when you run the Jenkins Groovy pipeline, then Jenkins adds its own environment to the script execution, it is not just running "bare" groove script (ie without exposed Jenkins commands and variables). Also, please keep in mind that when you run the Jenkins Groovy pipeline, then Jenkins adds its own environment to the script execution, it is not just running "bare" groove script (ie without exposed Jenkins commands and variables).

If you need to run a "bare" groovy script supporting the idea of Configuration as Code , one solution is to create a Bamboo Java/YAML spec .如果您需要运行支持Configuration as Code思想的“裸” groovy 脚本,一种解决方案是创建Bamboo Java/YAML 规范 Then you need to createScriptTask .然后你需要创建ScriptTask

// this is called when the plan and stages are created  
new Job("JobName","JobKey").tasks(new VcsCheckoutTask(), // to download the groovy script
   new ScriptTask().inlineBody("groovy me_myEvent.groovy").interpreterBinSh())

Note : your Bamboo build agent should have a pre-installed groovy.注意:您的Bamboo 构建代理应预先安装 groovy。

Another solution is to use the Bamboo plugin Groovy Tasks for Bamboo .另一种解决方案是使用 Bamboo 插件Groovy Tasks for Bamboo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM