Should we add scripts to a shell script file? On Monday, November 4, 2024 at 4:18:04 PM UTC+5:30 Chad Wilson wrote:
> You might want to look at > https://github.com/tomzo/gocd-yaml-config-plugin?tab=readme-ov-file#Validation > > The problem you have there is probably the `script:` task. Doesn't confirm > to documented syntax: > https://github.com/tomzo/gocd-yaml-config-plugin?tab=readme-ov-file#script > > Looks like you generated some nonsense with ChatGPT? :-) > > On Mon, Nov 4, 2024 at 6:35 PM Tanmoy santra <tanmoys...@gmail.com> wrote: > >> format_version: 10 >> pipelines: >> build_3d_models_service: >> group: 'defaultGroup' >> label_template: '${Appname}-${ENV}-${GO_PIPELINE_COUNTER}' >> parameters: >> Appname: '3d-models-service' >> Branch: 'master-java-21' # Default branch for the servercp repository >> JavaVersion: '21' >> ENV: 'staging-mumbai' # Deployment environment >> environment_variables: >> JAVA_HOME_21: '/usr/lib/jvm/java-21-openjdk' >> MAVEN_HOME: '/usr/share/java/maven' >> # AWS credentials should be set securely via GoCD environment variables >> or secrets >> materials: >> dockerfiles: >> git: >> url: 'g...@github.com:metiseduventures/adda-store-k8s.git' >> branch: 'dockerfile-adda-devo-21' >> destination: dockerfiles >> servercp: >> git: >> url: 'g...@github.com:metiseduventures/servercp.git' >> branch: '${Branch}' >> destination: servercp >> deployment_repo: >> git: >> url: 'g...@github.com:metiseduventures/adda-store-k8s.git' >> branch: '${ENV}' >> destination: deployment_repo >> stages: >> - name: BuildAndDeploy >> jobs: >> - name: BuildAndPush >> tasks: >> - script: >> shell: bash >> command: | >> #!/bin/bash >> set -e # Exit immediately if a command exits with a non-zero status >> >> # **Set up environment variables** >> echo "Setting up environment variables..." >> if [ "${ENV}" == "production" ]; then >> accountid="490891715875" >> else >> accountid="436568657448" >> fi >> DOCKERHUB_USERNAME="${accountid}.dkr.ecr.ap-south-1.amazonaws.com" >> APP_NAME="${Appname}" >> BUILD_TIME=$(date +"%d-%h_%H:%M:%S") >> IMAGE_TAG="${GO_PIPELINE_COUNTER}-${Branch}-${ENV}-${BUILD_TIME}" >> IMAGE_NAME="${DOCKERHUB_USERNAME}/${APP_NAME}" >> >> # Set JAVA_HOME based on JavaVersion >> if [ "${JavaVersion}" == "21" ]; then >> export JAVA_HOME="${JAVA_HOME_21}" >> fi >> >> export PATH=$JAVA_HOME/bin:${MAVEN_HOME}/bin:$PATH >> >> echo "JAVA_HOME is set to ${JAVA_HOME}" >> echo "Maven home is set to ${MAVEN_HOME}" >> >> # **Ensure GOCD_WORKING_DIR is set** >> if [ -z "${GOCD_WORKING_DIR}" ]; then >> export GOCD_WORKING_DIR=$(pwd) >> fi >> >> # **Build Dependencies** >> >> echo "Building dependencies..." >> >> # Build common-search-dto >> cd "${GOCD_WORKING_DIR}/servercp/common-search-dto" >> mvn clean install >> >> # Build commons-parent >> cd "${GOCD_WORKING_DIR}/servercp/commons-parent" >> git checkout 'ha-release-skills-21' >> git pull origin 'ha-release-skills-21' >> mvn clean install >> >> # Return to working directory >> cd "${GOCD_WORKING_DIR}" >> >> # **Build Main Application** >> >> echo "Building main application ${APP_NAME}..." >> >> cd "${GOCD_WORKING_DIR}/servercp/models/${APP_NAME}" >> mvn clean install -Dmaven.test.skip=true >> >> # **Build and Push Docker Image** >> >> echo "Building and pushing Docker image..." >> cd "${GOCD_WORKING_DIR}/servercp/models/${APP_NAME}/target" >> cp "${GOCD_WORKING_DIR}/dockerfiles/Dockerfile.${APP_NAME}" . >> cp "${GOCD_WORKING_DIR}/dockerfiles/.dockerignore" . >> >> # AWS ECR login >> aws ecr get-login-password --region ap-south-1 | docker login --username >> AWS --password-stdin "${DOCKERHUB_USERNAME}" >> >> # Build and push Docker image using Buildx >> docker buildx build --platform linux/amd64,linux/arm64 \ >> -t "${IMAGE_NAME}:${IMAGE_TAG}" \ >> -f "Dockerfile.${APP_NAME}" . --push >> >> # Export variables for next tasks >> echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GOCD_ENV_FILE" >> echo "IMAGE_TAG=${IMAGE_TAG}" >> "$GOCD_ENV_FILE" >> >> - script: >> shell: bash >> command: | >> #!/bin/bash >> set -e # Exit immediately if a command exits with a non-zero status >> >> # **Update Deployment Files in GitHub** >> >> echo "Updating deployment files in GitHub..." >> >> # Ensure GOCD_WORKING_DIR is set >> if [ -z "${GOCD_WORKING_DIR}" ]; then >> export GOCD_WORKING_DIR=$(pwd) >> fi >> >> # Set variables >> DEPLOY_REPO_DIR='deployment_repo' >> BRANCH_NAME="${ENV}" >> DEPLOYMENT_FILE="3d-models-servicestaging-mumbai.yml" >> >> # Navigate to the deployment repository >> cd "${GOCD_WORKING_DIR}/${DEPLOY_REPO_DIR}" >> >> # Ensure we're on the correct branch >> git checkout "${BRANCH_NAME}" >> git pull origin "${BRANCH_NAME}" >> >> # Update deployment file >> # Replace the image tag in the deployment file >> sed -i "s|^\(\s*image:\s*\).*|\1${IMAGE_NAME}:${IMAGE_TAG}|" >> "${DEPLOYMENT_FILE}" >> >> # Commit and push changes >> git config user.email "email" >> git config user.name "name" >> git add "${DEPLOYMENT_FILE}" >> git commit -m "Update ${Appname} image to ${IMAGE_TAG}" >> git push origin "${BRANCH_NAME}" >> >> echo "Deployment files updated successfully." >> >> # Optional: Send notification after updating deployment files >> - script: >> shell: bash >> command: | >> #!/bin/bash >> # **Send Slack Notification** >> echo "Sending Slack notification..." >> curl --location --request POST ' >> https://chat.googleapis.com/v1/spaces/AAAAteeAa0k/messages?key=your-key&token=your-token' >> >> \ >> --header 'Content-Type: application/json' \ >> --data-raw '{"text":"Deployment of '${Appname}' with Tag '${IMAGE_TAG}' >> in '${ENV}' Environment started. Deployment files updated."}' >> using this getting this error - >> >> - pipeline.gocd.yaml; 1. Failed to parse pipeline >> build_3d_models_service; class java.util.LinkedHashMap cannot be cast to >> class java.lang.String (java.util.LinkedHashMap and java.lang.String are >> in >> module java.base of loader 'bootstrap') ----- How to fix this error? >> and what is the error? >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "go-cd" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to go-cd+un...@googlegroups.com. >> To view this discussion visit >> https://groups.google.com/d/msgid/go-cd/6f5d1a8c-df8e-48a4-8109-9423d2c503efn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/go-cd/6f5d1a8c-df8e-48a4-8109-9423d2c503efn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "go-cd" group. To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/go-cd/1a20f86e-6434-4894-93bf-25f9bb28d3e9n%40googlegroups.com.