0

I am trying to write a gitlab CI file as follows:

image: ubuntu:latest

variables:
    GIT_SUBMODULE_STRATEGY: recursive
    AWS_DEFAULT_REGION: eu-central-1
    S3_BUCKET: $BUCKET_TRIAL

stages:
    - deploy

.before_script_template: &before_script_definition
    stage: deploy
    before_script:
        - apt-get -y update
        - apt-get -y install python3-pip python3.7 zip
        - python3.7 -m pip install --upgrade pip
        - python3.7 -V
        - pip3.7 install virtualenv

.after_script_template: &after_script_definition
    after_script:
        # Upload package to S3
        # Install AWS CLI
        - pip install awscli --upgrade # --user
        - export PATH=$PATH:~/.local/bin  # Add to PATH

        # Configure AWS connection
        - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
        - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
        - aws configure set default.region $AWS_DEFAULT_REGION
        - aws sts get-caller-identity --output text --query 'Account'  # current account
        - aws s3 cp ~/forlambda/archive.zip $BUCKET_TRIAL/${LAMBDA_NAME}-deployment.zip

monatliche_strom:
    variables:
        LAMBDA_NAME: monthly_strom
    before_script: *before_script_definition
    script:
        - mv some.py ~
        - mv requirements.txt ~

        # Move submodules
        - mv submodule1/submodule1 ~
        - mv submodule1/submodule2/submodule2 ~

        # Setup virtual environment
        - mkdir ~/forlambda
        - cd ~/forlambda
        - virtualenv -p python3 venv
        - source venv/bin/activate

        - pip3.7 install -r ~/requirements.txt -t ~/forlambda/venv/lib/python3.7/site-packages/

        # Package environment and dependencies
        - cd ~/forlambda/venv/lib/python3.7/site-packages/
        - zip -r9 ~/forlambda/archive.zip .
        - cd ~
        - zip -g ~/forlambda/archive.zip some.py
        - zip -r ~/forlambda/archive.zip submodule1/*
        - zip -r ~/forlambda/archive.zip submodule2/*
    after_script: *after_script_definition

When I run it in the gitlab CI lint, it gives me the following error:

jobs:monatliche_strom:before_script config should be an array containing strings and arrays of strings

jobs:monatliche_strom:after_script config should be an array containing strings and arrays of strings

I am fairly new to gitlab CI, so can someone please tell what is the mistake I am doing?

1 Answer 1

1

Try this:

image: ubuntu:latest

variables:
    GIT_SUBMODULE_STRATEGY: recursive
    AWS_DEFAULT_REGION: eu-central-1
    S3_BUCKET: $BUCKET_TRIAL

stages:
    - deploy

.before_script_template: &before_script_definition
    stage: deploy
    before_script:
        - apt-get -y update
        - apt-get -y install python3-pip python3.7 zip
        - python3.7 -m pip install --upgrade pip
        - python3.7 -V
        - pip3.7 install virtualenv

.after_script_template: &after_script_definition
    after_script:
        # Upload package to S3
        # Install AWS CLI
        - pip install awscli --upgrade # --user
        - export PATH=$PATH:~/.local/bin  # Add to PATH
        # Configure AWS connection
        - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
        - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
        - aws configure set default.region $AWS_DEFAULT_REGION
        - aws sts get-caller-identity --output text --query 'Account'  # current account
        - aws s3 cp ~/forlambda/archive.zip $BUCKET_TRIAL/${LAMBDA_NAME}-deployment.zip

monatliche_strom:
    variables:
        LAMBDA_NAME: monthly_strom
    <<: *before_script_definition
    script:
        - mv some.py ~
        - mv requirements.txt ~
        # Move submodules
        - mv submodule1/submodule1 ~
        - mv submodule1/submodule2/submodule2 ~
        # Setup virtual environment
        - mkdir ~/forlambda
        - cd ~/forlambda
        - virtualenv -p python3 venv
        - source venv/bin/activate
        - pip3.7 install -r ~/requirements.txt -t ~/forlambda/venv/lib/python3.7/site-packages/
        # Package environment and dependencies
        - cd ~/forlambda/venv/lib/python3.7/site-packages/
        - zip -r9 ~/forlambda/archive.zip .
        - cd ~
        - zip -g ~/forlambda/archive.zip some.py
        - zip -r ~/forlambda/archive.zip submodule1/*
        - zip -r ~/forlambda/archive.zip submodule2/*
    <<: *after_script_definition

Since you already described before_script & after_script in the anchors, you have to use << to merge the given hash into the current one

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, yes. I didnt notice it. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.