From 2a5717a29e76623cae12e232203c210e59012c01 Mon Sep 17 00:00:00 2001 From: Sergey Verbitskiy Date: Fri, 5 Jun 2020 12:58:46 +0300 Subject: [PATCH 1/3] Added exportDslToGit procedure --- dsl/procedures/exportDslToGit/form.xml | 266 ++++++++++++++++++ dsl/procedures/exportDslToGit/procedure.dsl | 71 +++++ .../exportDslToGit/steps/cleanup.groovy | 1 + 3 files changed, 338 insertions(+) create mode 100644 dsl/procedures/exportDslToGit/form.xml create mode 100644 dsl/procedures/exportDslToGit/procedure.dsl create mode 100644 dsl/procedures/exportDslToGit/steps/cleanup.groovy diff --git a/dsl/procedures/exportDslToGit/form.xml b/dsl/procedures/exportDslToGit/form.xml new file mode 100644 index 00000000..b5fcc3bd --- /dev/null +++ b/dsl/procedures/exportDslToGit/form.xml @@ -0,0 +1,266 @@ + + + + entry + + rsrcName + 1 + local + The resource where the DSL files will be checked out from git and imported to the Flow server. The directory on this resource must be accessible from the Flow server. + + + entry + + dest + 1 + The directory on the resource where the source tree will be created and from where the DSL files are read to be imported in Flow server. This directory must be accessible from the Flow server. In a clustered deployment, all Flow server nodes must have access to this directory. + + + checkbox + + cleanup + 1 + 0 + 0 + This option will delete the destination directory with the source tree after the job execution. + 0 + + + entry + + configuration + The name of a saved SCM configuration. + 1 + 1 + + + entry + + GitRepo + URL to the repository to pull from. ie: 'git://server/repo.git'. + 1 + + + + entry + + GitBranch + The name of the Git branch to use. ie: 'experimental'. + 0 + + + + checkbox + + clone + 1 + 0 + 1 + This option will clone a repository into a newly created directory. + 0 + + + + checkbox + + GitOverwrite + 1 + 0 + 0 + This option will overwrite a repository if it already exists. + 0 + + + entry + + objectType + 1 + Object type to generate DSL for. + + + entry + + objectName + 1 + Object name to generate DSL for. + + + entry + config + 1 + 1 + Previously defined configuration for the plugin + + + + textarea + files + 1 + Files pattern (GLOB) to use to add files to the commit. Each pattern per line. + + .> + + + textarea + message + 0 + Commit message for the newly created commit. If not provided, date and CloudBees CD Job ID will be used to identify the commit. + + + + entry + authorName + 0 + Name of the commit author. + + + + entry + authorEmail + 0 + Email of the author (the person who wrote the code). + + + + entry + committerName + 1 + Name of the committer (someone who has committed the code as opposed to the author). + + + + entry + committerEmail + 1 + Email of the committer. + + + + checkbox + removeMissing + If checked, the files that are missing from the repository will be removed from SCM. + + 1 + 0 + 0 + + + checkbox + failOnEmptyCommit + If checked, the procedure will fail if there is nothing to commit. + + 1 + 0 + 0 + + + + checkbox + + suppressNulls + 0 + 1 + 0 + 1 + Exclude from the generated DSL properties with null value. + + + + checkbox + + suppressDefaults + 0 + 1 + 0 + 0 + Exclude from the generated DSL properties with default value. + + + + checkbox + + suppressParent + 0 + 1 + 0 + 0 + Exclude from the generated DSL properties referred to object parent. + + + + checkbox + + includeAcls + 0 + 1 + 0 + 0 + Include in ACLs for objects. + + + + checkbox + + includeAclsInDifferentFile + 0 + 1 + 0 + 0 + Include ACLs for generated objects in different file. + + + + checkbox + + includeAllChildren + 0 + 1 + 0 + 0 + Include in the generated DSL all object children. If True - ignore value of 'Include Children' parameter. + + + + textarea + + includeChildren + 0 + Comma-separated list of object children the DSL should be generated for. + + + + checkbox + + includeChildrenInSameFile + 0 + 1 + 0 + 0 + Include in the generated DSL all object children. If True - ignore value of 'Include Children' parameter. + + + + textarea + + childrenInDifferentFile + 0 + Comma-separated list of patterns to include, like pipelines, procedures.*, applications.applicationTiers.components + + + diff --git a/dsl/procedures/exportDslToGit/procedure.dsl b/dsl/procedures/exportDslToGit/procedure.dsl new file mode 100644 index 00000000..e6bc6793 --- /dev/null +++ b/dsl/procedures/exportDslToGit/procedure.dsl @@ -0,0 +1,71 @@ +import java.io.File + +def procName = 'exportDslToGit' +procedure procName, { + jobNameTemplate = 'export-dsl-to-git-$[jobId]' + + step 'checkoutDsl', + subprocedure: 'CheckoutCode', + subproject:'/plugins/ECSCM-Git/project', + resourceName: '$[rsrcName]', + errorHandling: 'abortProcedure', + actualParameter: [ + clone: '$[clone]', + commit: 'HEAD', + config: '$[configuration]', + depth: '1', + dest: '$[dest]', + GitBranch: '$[GitBranch]', + GitRepo: '$[GitRepo]', + overwrite: '$[GitOverwrite]', + ] + + step 'generateDslToDirectory', + subprocedure: 'generateDslToDirectory', + errorHandling: 'abortProcedure', + actualParameter: [ + directory: '$[dest]', + objectType: '$[objectType]', + objectName: '$[objectName]', + pool: '$[rsrcName]', + suppressNulls: '$[suppressNulls]', + suppressDefaults: '$[suppressDefaults]', + suppressParent: '$[suppressParent]', + includeAcls: '$[includeAcls]', + includeAclsInDifferentFile: '$[includeAclsInDifferentFile]', + includeAllChildren: '$[includeAllChildren]', + includeChildren: '$[includeChildren]', + includeChildrenInSameFile: '$[includeChildrenInSameFile]', + childrenInDifferentFile: '$[childrenInDifferentFile]' + ] + + step 'exportDslToGit', + subprocedure: 'Commit', + subproject:'/plugins/EC-Git/project', + resourceName: '$[rsrcName]', + errorHandling: 'abortProcedure', + actualParameter: [ + authorEmail: '$[authorEmail]', + authorName: '$[authorName]', + committerEmail: '$[committerEmail]', + committerName: '$[committerName]', + config: '$[config]', + failOnEmptyCommit: '$[failOnEmptyCommit]', + files: '$[files]', + gitRepoFolder: '$[dest]', + message: '$[message]', + push: 'true', + removeMissing: '$[removeMissing]' + ] + + step 'cleanup', { + condition = '''$[/javascript + var cleanup= \'$[cleanup]\'; + (cleanup== \'true\' || cleanup== \'1\') ; + ]''' + alwaysRun = '1' + command = new File(pluginDir, "dsl/procedures/$procName/steps/cleanup.groovy").text + resourceName = '$[rsrcName]' + shell = 'ec-groovy' + } +} \ No newline at end of file diff --git a/dsl/procedures/exportDslToGit/steps/cleanup.groovy b/dsl/procedures/exportDslToGit/steps/cleanup.groovy new file mode 100644 index 00000000..7e021ad0 --- /dev/null +++ b/dsl/procedures/exportDslToGit/steps/cleanup.groovy @@ -0,0 +1 @@ +new File("$[dest]").deleteDir() \ No newline at end of file From 56816b99cbd0c8483c299a34b1782f9d16e5c316 Mon Sep 17 00:00:00 2001 From: Sergey Verbitskiy Date: Fri, 5 Jun 2020 15:01:56 +0300 Subject: [PATCH 2/3] code review corrections --- dsl/procedures/exportDslToGit/form.xml | 33 +++------------------ dsl/procedures/exportDslToGit/procedure.dsl | 6 ++-- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/dsl/procedures/exportDslToGit/form.xml b/dsl/procedures/exportDslToGit/form.xml index b5fcc3bd..dcea9a9f 100644 --- a/dsl/procedures/exportDslToGit/form.xml +++ b/dsl/procedures/exportDslToGit/form.xml @@ -43,8 +43,8 @@ entry - - configuration + + checkoutConfig The name of a saved SCM configuration. 1 1 @@ -65,17 +65,6 @@ 0 - - checkbox - - clone - 1 - 0 - 1 - This option will clone a repository into a newly created directory. - 0 - - checkbox @@ -102,11 +91,11 @@ entry - config + commitConfig 1 1 Previously defined configuration for the plugin - + textarea @@ -123,20 +112,6 @@ Commit message for the newly created commit. If not provided, date and CloudBees CD Job ID will be used to identify the commit. - - entry - authorName - 0 - Name of the commit author. - - - - entry - authorEmail - 0 - Email of the author (the person who wrote the code). - - entry committerName diff --git a/dsl/procedures/exportDslToGit/procedure.dsl b/dsl/procedures/exportDslToGit/procedure.dsl index e6bc6793..a30f97ff 100644 --- a/dsl/procedures/exportDslToGit/procedure.dsl +++ b/dsl/procedures/exportDslToGit/procedure.dsl @@ -10,9 +10,9 @@ procedure procName, { resourceName: '$[rsrcName]', errorHandling: 'abortProcedure', actualParameter: [ - clone: '$[clone]', + clone: 'true', commit: 'HEAD', - config: '$[configuration]', + config: '$[checkoutConfig]', depth: '1', dest: '$[dest]', GitBranch: '$[GitBranch]', @@ -49,7 +49,7 @@ procedure procName, { authorName: '$[authorName]', committerEmail: '$[committerEmail]', committerName: '$[committerName]', - config: '$[config]', + config: '$[commitConfig]', failOnEmptyCommit: '$[failOnEmptyCommit]', files: '$[files]', gitRepoFolder: '$[dest]', From 70d9d9c6a7b6efdde1a01b841dd6d969b016cae1 Mon Sep 17 00:00:00 2001 From: Sergey Verbitskiy Date: Wed, 4 Nov 2020 15:03:50 +0200 Subject: [PATCH 3/3] refactored plugin to use EC-Git Pull and Clone procedures instead of ECSCM-Git plugin procedures --- dsl/procedures/exportDslToGit/form.xml | 63 +++++++++++-------- dsl/procedures/exportDslToGit/procedure.dsl | 45 +++++++------ dsl/procedures/importDslFromGit/form.xml | 15 ++--- dsl/procedures/importDslFromGit/procedure.dsl | 31 ++++++--- 4 files changed, 95 insertions(+), 59 deletions(-) diff --git a/dsl/procedures/exportDslToGit/form.xml b/dsl/procedures/exportDslToGit/form.xml index dcea9a9f..c37a8177 100644 --- a/dsl/procedures/exportDslToGit/form.xml +++ b/dsl/procedures/exportDslToGit/form.xml @@ -41,40 +41,51 @@ This option will delete the destination directory with the source tree after the job execution. 0 + + checkbox + + clone + 1 + 0 + 0 + This option will clone a repository into a newly created directory. + 0 + + + + checkbox + + GitOverwrite + 1 + 0 + 0 + This option will overwrite a repository if it already exists. + 0 + entry - - checkoutConfig - The name of a saved SCM configuration. + + gitConfig + The name of a saved Git configuration. 1 1 entry - - GitRepo + + repoUrl URL to the repository to pull from. ie: 'git://server/repo.git'. 1 entry - - GitBranch + + branch The name of the Git branch to use. ie: 'experimental'. 0 - - checkbox - - GitOverwrite - 1 - 0 - 0 - This option will overwrite a repository if it already exists. - 0 - entry @@ -89,14 +100,6 @@ 1 Object name to generate DSL for. - - entry - commitConfig - 1 - 1 - Previously defined configuration for the plugin - - textarea files @@ -238,4 +241,14 @@ Comma-separated list of patterns to include, like pipelines, procedures.*, applications.applicationTiers.components + + entry + + tag + Provide the name of a specific tag to checkout after the clone command. + 0 + clone + ${clone} == "1" + + diff --git a/dsl/procedures/exportDslToGit/procedure.dsl b/dsl/procedures/exportDslToGit/procedure.dsl index a30f97ff..1e4bbc8c 100644 --- a/dsl/procedures/exportDslToGit/procedure.dsl +++ b/dsl/procedures/exportDslToGit/procedure.dsl @@ -4,21 +4,32 @@ def procName = 'exportDslToGit' procedure procName, { jobNameTemplate = 'export-dsl-to-git-$[jobId]' - step 'checkoutDsl', - subprocedure: 'CheckoutCode', - subproject:'/plugins/ECSCM-Git/project', - resourceName: '$[rsrcName]', - errorHandling: 'abortProcedure', - actualParameter: [ - clone: 'true', - commit: 'HEAD', - config: '$[checkoutConfig]', - depth: '1', - dest: '$[dest]', - GitBranch: '$[GitBranch]', - GitRepo: '$[GitRepo]', - overwrite: '$[GitOverwrite]', - ] + step 'Clone', + subprocedure: 'Clone', + subproject: '/plugins/EC-Git/project', + condition: '$[/myJob/actualParameters/clone]', + errorHandling:'abortProcedure', + resourceName: '$[rsrcName]', + actualParameter: [ + branch: '$[branch]', + config: '$[gitConfig]', + gitRepoFolder: '$[dest]', + overwrite: '$[GitOverwrite]', + repoUrl: '$[repoUrl]', + tag: '$[tag]' + ] + + step 'Pull', + subprocedure: 'Pull', + subproject: '/plugins/EC-Git/project', + resourceName: '$[rsrcName]', + errorHandling: 'abortProcedure', + actualParameter: [ + branch: '$[branch]', + config: '$[gitConfig]', + gitRepoFolder: '$[dest]', + repoUrl: '$[repoUrl]', + ] step 'generateDslToDirectory', subprocedure: 'generateDslToDirectory', @@ -45,11 +56,9 @@ procedure procName, { resourceName: '$[rsrcName]', errorHandling: 'abortProcedure', actualParameter: [ - authorEmail: '$[authorEmail]', - authorName: '$[authorName]', committerEmail: '$[committerEmail]', committerName: '$[committerName]', - config: '$[commitConfig]', + config: '$[gitConfig]', failOnEmptyCommit: '$[failOnEmptyCommit]', files: '$[files]', gitRepoFolder: '$[dest]', diff --git a/dsl/procedures/importDslFromGit/form.xml b/dsl/procedures/importDslFromGit/form.xml index a1ac986f..4bde9726 100644 --- a/dsl/procedures/importDslFromGit/form.xml +++ b/dsl/procedures/importDslFromGit/form.xml @@ -44,7 +44,7 @@ checkbox - + overwrite 0 1 @@ -54,16 +54,16 @@ entry - - config + + gitConfig The name of a saved SCM configuration. 1 1 entry - - GitRepo + + repoUrl URL to the repository to pull from. ie: 'git://server/repo.git'. 1 @@ -77,8 +77,9 @@ entry - - GitBranch + + branch + master The name of the Git branch to use. ie: 'experimental'. 0 diff --git a/dsl/procedures/importDslFromGit/procedure.dsl b/dsl/procedures/importDslFromGit/procedure.dsl index 46bbeba6..92e89b82 100644 --- a/dsl/procedures/importDslFromGit/procedure.dsl +++ b/dsl/procedures/importDslFromGit/procedure.dsl @@ -4,22 +4,35 @@ def procName = 'importDslFromGit' procedure procName, { jobNameTemplate = 'import-dsl-from-git-$[jobId]' - step 'checkoutDsl', - subprocedure: 'CheckoutCode', - subproject:'/plugins/ECSCM-Git/project', + step 'Clone', + subprocedure: 'Clone', + subproject: '/plugins/EC-Git/project', + condition: '$[/myJob/actualParameters/clone]', resourceName: '$[rsrcName]', errorHandling: 'abortProcedure', actualParameter: [ - clone: '$[clone]', + branch: '$[branch]', commit: '$[commit]', - config: '$[config]', + config: '$[gitConfig]', depth: '$[depth]', - dest: '$[dest]', - GitBranch: '$[GitBranch]', - GitRepo: '$[GitRepo]', + gitRepoFolder: '$[dest]', overwrite: '$[GitOverwrite]', + repoUrl: '$[repoUrl]', tag: '$[tag]' - ] + ] + + step 'Pull', + subprocedure: 'Pull', + subproject: '/plugins/EC-Git/project', + resourceName: '$[rsrcName]', + errorHandling: 'abortProcedure', + actualParameter: [ + branch: '$[branch]', + config: '$[gitConfig]', + gitRepoFolder: '$[dest]', + repoUrl: '$[repoUrl]', + ] + step 'installFromDirectory', subprocedure: 'installDslFromDirectory',