简体   繁体   中英

Jenkins to Bamboo Migration & Running Groovy

I'm fairly new to Jenkins and a total newbie to Bamboo. I have a Jenkins Pipeline and I'm trying to create an equivalent in Bamboo (I believe it's called a Plan).

I've got some groovy code that I want to run in my Bamboo plan.

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

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:

@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 .

Can I achieve the same thing in Bamboo using the script task? What would this look like in Bamboo?

The short answer is NO , as Atlassian Bamboo doesn't support the DSL Groovy or Scripted Groovy pipeline . 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 . Then you need to createScriptTask .

// 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.

Another solution is to use the Bamboo plugin Groovy Tasks for Bamboo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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