Skip to content

Commit

Permalink
improve jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
reschandreas committed Jan 10, 2024
1 parent b8cc21a commit baa6e7b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 79 deletions.
2 changes: 1 addition & 1 deletion cli/examples/example-windfile-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ actions:
- name: clean_up
script: |
rm -rf aeolus/
runAlways: true
runAlways: true
151 changes: 73 additions & 78 deletions cli/templates/Jenkinsfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}') {
Expand All @@ -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 %}
}

0 comments on commit baa6e7b

Please sign in to comment.