From b61a06834e83e10372559b91e92f0cd42284f9ef Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Thu, 13 Mar 2025 23:41:04 +0100 Subject: [PATCH] Fix publish jobs in gitlab-ci.yml to guarantee full replace in FTP Signed-off-by: garciadeblas --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ff4decd..09717f57 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,6 @@ variables: DEBIAN_FRONTEND: "noninteractive" LC_ALL: "C.UTF-8" LANG: "C.UTF-8" - REPOSITORY_URL: "https://osm.etsi.org/gerrit/osm/osmclient.git" SFTP_SERVER: "vnf-catalog.etsi.org" SFTP_PORT: "29419" SFTP_USER: "osmsupport" @@ -57,14 +56,28 @@ publish-testing-repository: script: - apt update && apt install -y sshpass - | + echo "Uploading new files to Testing-new..." sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF - put -r vnf-catalog/* Testing + mkdir Testing-new + put -r vnf-catalog/* Testing-new/ + EOF + + echo "Switching directories..." + sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF + rename Testing Testing-old + rename Testing-new Testing + EOF + + echo "Cleaning up old files..." + sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF + rm -rf Testing-old EOF rules: - - if: '$CI_COMMIT_REF_NAME == "master"' # Only in master + - if: '$CI_COMMIT_REF_NAME == "master"' # Only in master when: on_success # - if: '$CI_COMMIT_REF_PROTECTED == "true"' # when: on_success + allow_failure: true ############################################################################### # Job to publish artifacts on demand (publication to Testing) @@ -77,10 +90,25 @@ publish-ondemand-repository: script: - apt update && apt install -y sshpass - | - DESTINATION_FOLDER="${ONDEMAND_DESTINATION_FOLDER:-Testing}" - echo "Uploading files to folder $DESTINATION_FOLDER in FTP ..." + DESTINATION_FOLDER="${ONDEMAND_DESTINATION_FOLDER:-Stable}" + TEMP_FOLDER="${DESTINATION_FOLDER}-new" + BACKUP_FOLDER="${DESTINATION_FOLDER}-old" + + echo "Uploading files to temporary folder $TEMP_FOLDER in FTP ..." + sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF + mkdir $TEMP_FOLDER + put -r vnf-catalog/* $TEMP_FOLDER/ + EOF + + echo "Switching directories..." + sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF + rename $DESTINATION_FOLDER $BACKUP_FOLDER + rename $TEMP_FOLDER $DESTINATION_FOLDER + EOF + + echo "Cleaning up old files..." sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF - put -r vnf-catalog/* $DESTINATION_FOLDER + rm -rf $BACKUP_FOLDER EOF when: manual # This job is run on demand allow_failure: true -- GitLab