diff mbox series

[v3,1/6] gitlab-ci: Extract &environment_variables template

Message ID 20210519184549.2192728-2-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series gitlab-ci: Allow using FreeBSD runners | expand

Commit Message

Philippe Mathieu-Daudé May 19, 2021, 6:45 p.m. UTC
To be able to set the same environment variables to multiple jobs,
extract what we currently have as a template.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 .gitlab-ci.d/buildtest-template.yml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Willian Rampazzo May 19, 2021, 7:12 p.m. UTC | #1
On Wed, May 19, 2021 at 3:46 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> To be able to set the same environment variables to multiple jobs,
> extract what we currently have as a template.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  .gitlab-ci.d/buildtest-template.yml | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Wainer dos Santos Moschetta May 20, 2021, 6 p.m. UTC | #2
Hi,

On 5/19/21 3:45 PM, Philippe Mathieu-Daudé wrote:
> To be able to set the same environment variables to multiple jobs,
> extract what we currently have as a template.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   .gitlab-ci.d/buildtest-template.yml | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
> index 32aaef1a213..58b01744751 100644
> --- a/.gitlab-ci.d/buildtest-template.yml
> +++ b/.gitlab-ci.d/buildtest-template.yml
> @@ -1,8 +1,11 @@
> +.environment_variables_template:
> +  before_script:
> +    - JOBS=$(expr $(nproc) + 1)
> +

I wish we could wrap environment variables definitions in `variables` 
(https://docs.gitlab.com/ee/ci/yaml/README.html#variables) instead of 
`before_scripts`, but it wouldn't evaluate the shell expressions.

Unless I am wrong, if the job definition has its own `before_script` 
then including `.environment_variables_template` won't take effect. 
Shouldn't it be documented?

- Wainer

>   .native_build_job_template:
>     stage: build
>     image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest
> -  before_script:
> -    - JOBS=$(expr $(nproc) + 1)
> +  extends: .environment_variables_template
>     script:
>       - if test -n "$LD_JOBS";
>         then
diff mbox series

Patch

diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
index 32aaef1a213..58b01744751 100644
--- a/.gitlab-ci.d/buildtest-template.yml
+++ b/.gitlab-ci.d/buildtest-template.yml
@@ -1,8 +1,11 @@ 
+.environment_variables_template:
+  before_script:
+    - JOBS=$(expr $(nproc) + 1)
+
 .native_build_job_template:
   stage: build
   image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest
-  before_script:
-    - JOBS=$(expr $(nproc) + 1)
+  extends: .environment_variables_template
   script:
     - if test -n "$LD_JOBS";
       then