pipeline {
    agent any

    environment {
        DOCKER_IMAGE = 'docker.cloud.pokash.pl/ably-webui'
        DOCKER_REGISTRY = 'docker.cloud.pokash.pl'
        GIT_REPO = 'https://repo.pokash.pl/POKASH.PL/ably.do.git'
        REGISTRY_CREDENTIALS_ID = '2753fc17-5ad1-4c78-b86a-a3e54c543adc' // ID poświadczeń do lokalnego rejestru
    }

    stages {
        stage('Checkout') {
            steps {
                git url: "${GIT_REPO}", branch: 'main/webui'
            }
        }

        stage('Build Docker Image') {
            steps {
                script {
                    docker.build("${DOCKER_IMAGE}:latest")
                }
            }
        }

        stage('Push Docker Image') {
            steps {
                script {
                    // Logowanie do lokalnego rejestru
                    docker.withRegistry("http://${DOCKER_REGISTRY}", "${REGISTRY_CREDENTIALS_ID}") {
                        docker.image("${DOCKER_IMAGE}:latest").push('latest')
                    }
                }
            }
        }
    }

    post {
        always {
            cleanWs() // Czyści workspace po zakończeniu builda
        }
    }
}