0

I have the following groovy script which configures my freshly installed Jenkins instance:

#!groovy import hudson.security.* import jenkins.model.* import hudson.util.*; import jenkins.install.*; import jenkins.model.Jenkins import jenkins.model.JenkinsLocationConfiguration // parameters def jenkinsParameters = [ email: '{{ jenkins_username_name }} <{{ jenkins_username_email }}>', url: '{{ jenkins_tls_url }}' ] // get Jenkins location configuration def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get() // set Jenkins URL jenkinsLocationConfiguration.setUrl(jenkinsParameters.url) // set Jenkins admin email address jenkinsLocationConfiguration.setAdminAddress(jenkinsParameters.email) def instance = Jenkins.getInstance() def hudsonRealm = new HudsonPrivateSecurityRealm(false) hudsonRealm.createAccount('{{ jenkins_admin_username }}', '{{ jenkins_admin_password }}') instance.setSecurityRealm(hudsonRealm) instance.setInstallState(InstallState.INITIAL_SETUP_COMPLETED) jenkinsLocationConfiguration.save() instance.save() 

I would like to create a pipeline by using the Jenkinsfile below also via groovy script:

pipeline { agent any stages { stage('Buzz Buzz') { steps { echo 'Bees Buzz!' } } stage('Bees Bees Bees') { steps { echo 'Buzz, Bees, Buzz!' echo 'Bees Buzzing!' } } } } 

How can I create this pipeline via Groovy script?

1 Answer 1

1
def jobDSL=""" pipeline { agent any stages { stage('Buzz Buzz') { steps { echo 'Bees Buzz!' } } stage('Bees Bees Bees') { steps { echo 'Buzz, Bees, Buzz!' echo 'Bees Buzzing!' } } } } """; def flowDefinition = new org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition(jobDSL, true); def parent = Jenkins.instance; def job = new org.jenkinsci.plugins.workflow.job.WorkflowJob(parent, "testJob") job.definition = flowDefinition Jenkins.instance.reload() 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.