3

I have the following project:

enter image description here

Inside the file .gitlab-ci.yml I have a script that I run writen in different lines:

deploy-uat:
  <<: *job_definition
  image: myimage 
  stage: publish
  script:
    - if [[ $START_DATE == "" ]]; then echo "START_DATE is empty"; exit 1; fi;
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'kinit ad1frdqscuat@DATAUAT.EDHV2 -kt /etc/security/keytabs/ad1frdqscuat.keytab'
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'rm -rf /opt/application/UAT/1FR/DQSC/contracts/'
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'mkdir /opt/application/UAT/1FR/DQSC/contracts/'
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'rm -rf /opt/application/UAT/1FR/DQSC/jar/'
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'mkdir /opt/application/UAT/1FR/DQSC/jar/'
    - scp $JAR_PATH $USER@$SERVER:/opt/application/UAT/1FR/DQSC/jar/
    - scp $CONTRACT_PATH $USER@$SERVER:/opt/application/UAT/1FR/DQSC/contracts/
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER 'chmod -R 755 /opt/application/UAT/1FR/DQSC/jar/'
    - ssh -o StrictHostKeyChecking=no $USER@$SERVER '/opt/application/UAT/1FR/DQSC/draguenelle/1.13.3/bin/deployEnricher.sh -f /opt/application/UAT/1FR/DQSC/contracts/*.xlsm -o PROFITABILITY_KPI -j /opt/application/UAT/1FR/DQSC/jar/dqsc-different-ip-bandwidth-assembly-*.jar -qo DQSC -qs DQSC -m enrichment -s ' $START_DATE'T00:00Z'
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"
      when: manual
  when: manual

I want to put all the content of script tag in a separate file that I will create in the project repository called for example script.sh and replace all the lines in the gitlab-ci.yml.

Charlotte
  • 111
  • 1
  • 9
mr.Penguin
  • 1,166
  • 1
  • 8
  • 24
  • 3
    Have you considered just calling the script? e.g. `script: ./myscript.sh` should do what you want, based on your description. – sytech Jun 28 '22 at 18:40

2 Answers2

5

You can just create a script.sh at your root level folder

Then in your script part within yml:

script:
  - chmod +x ./script.sh; ./script.sh

And also don't forget to remove the "-" character from the beginning of each line in your script file.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Ray
  • 1,539
  • 1
  • 14
  • 27
0

for me this worked

script:
 - chmod +x script.sh
 - source script.sh