From baa6e7b0f9e1734fd050e45d462d147ece886c87 Mon Sep 17 00:00:00 2001 From: Andreas Resch Date: Wed, 10 Jan 2024 22:07:02 +0100 Subject: [PATCH] improve jenkins --- cli/examples/example-windfile-readme.yml | 2 +- cli/templates/Jenkinsfile.j2 | 151 +++++++++++------------ 2 files changed, 74 insertions(+), 79 deletions(-) diff --git a/cli/examples/example-windfile-readme.yml b/cli/examples/example-windfile-readme.yml index 6c306e1b..e332b650 100644 --- a/cli/examples/example-windfile-readme.yml +++ b/cli/examples/example-windfile-readme.yml @@ -41,4 +41,4 @@ actions: - name: clean_up script: | rm -rf aeolus/ - runAlways: true \ No newline at end of file + runAlways: true diff --git a/cli/templates/Jenkinsfile.j2 b/cli/templates/Jenkinsfile.j2 index 02592f5f..92874c6b 100644 --- a/cli/templates/Jenkinsfile.j2 +++ b/cli/templates/Jenkinsfile.j2 @@ -39,100 +39,95 @@ pipeline { stages { {%- if repositories %} {%- for name, repository in repositories.items() %} - stage('{{ name }}') { - steps { - echo '🖨️ cloning aeolus' - dir('{{ repository.path }}') { - checkout([$class: 'GitSCM', - branches: [[name: '{{ repository.branch }}']], - doGenerateSubmoduleConfigurations: false, - userRemoteConfigs: [[ - {%- if metadata.gitCredentials %} - credentialsId: '{{ metadata.gitCredentials }}', - {%- endif %} - name: '{{ name }}', - {%- set url = '${%s}' % repo_metadata[name]["url"] %} - url: "{{ url }}" - ]] - ]) - } + stage('{{ name }}') { + steps { + echo '🖨️ cloning aeolus' + dir('{{ repository.path }}') { + checkout([$class: 'GitSCM', + branches: [[name: '{{ repository.branch }}']], + doGenerateSubmoduleConfigurations: false, + userRemoteConfigs: [[ + {%- if metadata.gitCredentials %} + credentialsId: '{{ metadata.gitCredentials }}', + {%- endif %} + name: '{{ name }}', + {%- set url = '${%s}' % repo_metadata[name]["url"] %} + url: "{{ url }}" + ]] + ]) } } + } {%- endfor -%} {%- endif %} {%- for step in steps %} - stage('{{ step.name }}') { - {%- if step.docker %} - agent { - docker { - {%- set dockerImage = "%s" % step.docker.image -%} - {%- if docker.tag -%} - {% set dockerImage = "{}:{}".format(dockerImage, step.docker.tag) %} - {%- endif %} - image '{{ dockerImage }}' - {%- if docker.parameters %} - args '{{ docker.parameters | join(' ') }}' - {%- endif %} - } - } - {%- if step.excludeDuring %} - when { - anyOf { - {%- for exclude in step.excludeDuring %} - expression { params.current_lifecycle != '{{ exclude | replace('Lifecycle.', '') }}' } - {%- endfor %} - } + stage('{{ step.name }}') { + {%- if step.docker %} + agent { + docker { + {%- set dockerImage = "%s" % step.docker.image -%} + {%- if docker.tag -%} + {% set dockerImage = "{}:{}".format(dockerImage, step.docker.tag) %} + {%- endif %} + image '{{ dockerImage }}' + {%- if docker.parameters %} + args '{{ docker.parameters | join(' ') }}' + {%- endif %} } - {%- endif %} - {%- if step.environment %} - environment { - {%- for env_var, env_value in step.environment.items %} - {{ env_var }} = '{{ env_value }}' - {%- endfor %} + } + {%- if step.excludeDuring %} + when { + anyOf { + {%- for exclude in step.excludeDuring %} + expression { params.current_lifecycle != '{{ exclude | replace('Lifecycle.', '') }}' } + {%- endfor %} } - {%- endif %} + } {%- endif %} - steps { - echo '⚙️ executing {{ step.name }}' - {%- if step.workdir %} - dir('{{ step.workdir }}') { - sh ''' - {{ step.script | indent(12, false) }} - ''' - } - {%- else %} + {%- if step.environment %} + environment { + {%- for env_var, env_value in step.environment.items %} + {{ env_var }} = '{{ env_value }}' + {%- endfor %} + } + {%- endif %} + {%- endif %} + steps { + echo '⚙️ executing {{ step.name }}' + {%- if step.workdir %} + dir('{{ step.workdir }}') { sh ''' - {{ step.script | indent(12, false) }} + {{ step.script | indent(12, false) }} ''' - {%- endif %} } + {%- else %} + sh ''' + {{ step.script | indent(12, false) }} + ''' + {%- endif %} } - {%- endfor %} + } + {%- endfor %} } - {%- if has_always_actions %} - post { +{%- if has_always_actions or has_results %} +post { + always { {%- for action in always_steps %} - always { - echo '⚙️ executing {{ action.name }}' - {%- if action.workdir %} - dir('{{ action.workdir }}') { - sh ''' - {{ action.script | indent(8, false) }} - ''' - } - {%- else %} + echo '⚙️ executing {{ action.name }}' + {%- if action.workdir %} + dir('{{ action.workdir }}') { sh ''' - {{ action.script | indent(6, false) }} + {{ action.script | indent(8, false) }} ''' - {%- endif %} } - {%- endfor %} - {%- if metadata.resultHook %} - - {%- endif %} + {%- else %} + sh ''' + {{ action.script | indent(6, false) }} + ''' + {%- endif %} + {%- endfor %} {%- if has_results %} - always { echo '📊 publishing results' {%- for workdir, entries in results.items() %} dir('{{ workdir }}') { @@ -145,17 +140,17 @@ pipeline { {%- endfor %} } {%- endfor %} - } {%- if metadata.resultHook %} - always { {%- if metadata.resultHookCredentials %} sendTestResults credentialsId: '{{ metadata.resultHookCredentials }}', notificationUrl: '{{ metadata.resultHook }}' {%- else %} sendTestResults notificationUrl: '{{ metadata.resultHook }}' {%- endif %} - } {%- endif %} {%- endif %} + {%- if has_always_actions or has_results %} + } } {%- endif %} + {%- endif %} }