pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps { checkout scm }
        }
        stage('Build') {
            steps {
                sh 'echo "Building the startup product..."'
            }
        }
        stage('Test') {
            steps {
                sh 'echo "Running tests..."'
                sh 'exit 0'
            }
        }
    }
    post {
        success {
            withCredentials([usernamePassword(
                credentialsId: 'gitea-token',
                usernameVariable: 'GITEA_USER',
                passwordVariable: 'GITEA_TOKEN')]) {
                sh '''
                    curl -s -X POST \
                      "https://git.ssw590.abrdns.com/api/v1/repos/StartupTeam/Strartup-product/statuses/${GIT_COMMIT}" \
                      -H "Authorization: token ${GITEA_TOKEN}" \
                      -H "Content-Type: application/json" \
                      -d '{"state":"success","context":"continuous-integration/jenkins","description":"Build passed"}'
                '''
            }
        }
        failure {
            withCredentials([usernamePassword(
                credentialsId: 'gitea-token',
                usernameVariable: 'GITEA_USER',
                passwordVariable: 'GITEA_TOKEN')]) {
                sh '''
                    curl -s -X POST \
                      "https://git.ssw590.abrdns.com/api/v1/repos/StartupTeam/Strartup-product/statuses/${GIT_COMMIT}" \
                      -H "Authorization: token ${GITEA_TOKEN}" \
                      -H "Content-Type: application/json" \
                      -d '{"state":"failure","context":"continuous-integration/jenkins","description":"Build failed"}'
                '''
            }
        }
    }
}