title: Duplicated code in .gitlab-ci.yml's script section
body: <p>Is there a way within gitlab ci to create something like a function? I would like to don't have the duplicated code in the stages or should I use a external script for such a task?</p>
  <p>I had a look into the gitlab template but with a template I can only use a job in the template once.</p>
  <pre><code>stages:
    - build-artefakts
    - build-image
  
  variables:
    CI_REGISTRY_NAMESPACE: 'main'
    CI_BASE_IMAGE: '...'
  
    1_GROUP_ID: '...'
    1_ARTIFACT_ID: '...'
    1_CLASSIFIER: '...'
    1_JAR_NAME: '...'
    1_IMAGE_NAME: '...'
  
    2_GROUP_ID: '...'
    2_ARTIFACT_ID: '...'
    2_CLASSIFIER: '...'
    2_JAR_NAME: '...'
    2_IMAGE_NAME: '...'
  
  
  deploy-maven:
    image: maven:3.6-jdk-11
    stage: build-artefakts
    script:
      - 'mvn deploy -f pom.xml -s ~config/maven/ci_settings.xml -P prod'
    only:
      - master
    artifacts:
      paths:
        - ./target
      expire_in: 1 weeks
  
  deploy-docker-1:
    image: $CI_BASE_IMAGE
    stage: build-image
    variables:
      ARTIFACT_ID: $1_ARTIFACT_ID
      JAR_NAME: $1_JAR_NAME
      IMAGE_NAME: $1_IMAGE_NAME
  
    before_script:
      - 'docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN  $CI_REGISTRY'
    script:
      - 'cd docker'
      - 'mv ../target/$ARTIFACT_ID/*.jar $JAR_NAME'
      - 'docker build . -t $IMAGE_NAME:$PROJECT_VERSION --build-arg JAR_FILE=$JAR_NAME'
      - 'docker tag $IMAGE_NAME:$PROJECT_VERSION $CI_REGISTRY/$CI_REGISTRY_NAMESPACE/$IMAGE_NAME:$PROJECT_VERSION'
      - 'docker push $CI_REGISTRY/$CI_REGISTRY_NAMESPACE/$IMAGE_NAME:$PROJECT_VERSION'
  
  deploy-docker-2:
    image: $CI_BASE_IMAGE
    stage: build-image
    variables:
      ARTIFACT_ID: $2_ARTIFACT_ID
      JAR_NAME: $2_JAR_NAME
      IMAGE_NAME: $2_IMAGE_NAME
  
    before_script:
      - 'docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN  $CI_REGISTRY'
    script:
      - 'cd docker'
      - 'mv ../target/$ARTIFACT_ID/*.jar $JAR_NAME'
      - 'docker build . -t $IMAGE_NAME:$PROJECT_VERSION --build-arg JAR_FILE=$JAR_NAME'
      - 'docker tag $IMAGE_NAME:$PROJECT_VERSION $CI_REGISTRY/$CI_REGISTRY_NAMESPACE/$IMAGE_NAME:$PROJECT_VERSION'
      - 'docker push $CI_REGISTRY/$CI_REGISTRY_NAMESPACE/$IMAGE_NAME:$PROJECT_VERSION'
  
  </code></pre>