Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Implement CI/CD Pipelines on Windows with Jenkins and PowerShell

Continuous Integration and Continuous Deployment (CI/CD) are essential practices in modern software development. They allow for automated testing, building, and deployment of applications, ensuring that new code changes are integrated smoothly and delivered to production efficiently. In a Windows environment, Jenkins is a popular tool for setting up CI/CD pipelines, and PowerShell can be used to automate various tasks within these pipelines.

Setting Up Jenkins on Windows

  1. Download and Install Jenkins:

    • Visit the Jenkins download page and download the Windows installer.
    • Run the installer and follow the setup wizard to install Jenkins as a Windows service.
  2. Configure Jenkins:

    • Open a web browser and navigate to http://localhost:8080.
    • Unlock Jenkins by entering the initial admin password found in C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword.
    • Install suggested plugins and create your first admin user.

Creating a Simple CI/CD Pipeline

  1. Install Git and PowerShell:

  2. Create a New Jenkins Pipeline:

    • In Jenkins, click on “New Item” and select “Pipeline”.
    • Name your pipeline and click “OK”.
  3. Configure the Pipeline Script:

    • In the pipeline configuration page, scroll down to the “Pipeline” section and select “Pipeline script”.
    • Enter the following sample Jenkinsfile script:
pipeline {
    agent any

    stages {
        stage('Clone Repository') {
            steps {
                git 'https://github.com/your-repo/sample-app.git'
            }
        }
        stage('Build') {
            steps {
                script {
                    bat 'dotnet build'
                }
            }
        }
        stage('Test') {
            steps {
                script {
                    bat 'dotnet test'
                }
            }
        }
        stage('Deploy') {
            steps {
                script {
                    powershell 'Deploy-Script.ps1'
                }
            }
        }
    }
}

Using PowerShell for Deployment

  1. Create a PowerShell Deployment Script:
    • Create a file named Deploy-Script.ps1 with the following content:
# Deploy-Script.ps1

Write-Host "Starting Deployment..."

# Example: Copy files to a deployment directory
Copy-Item -Path "C:\Jenkins\workspace\sample-app\bin\Release\netcoreapp3.1\*" -Destination "C:\inetpub\wwwroot\sample-app" -Recurse -Force

Write-Host "Deployment Completed!"
  1. Execute the Pipeline:
    • Save the pipeline configuration and click “Build Now” to execute the pipeline.
    • Monitor the console output to ensure each stage executes successfully.

Conclusion

By following these steps, you can set up a basic CI/CD pipeline on a Windows environment using Jenkins and PowerShell. This setup allows for automated testing, building, and deployment of your applications, enhancing your development workflow.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.