Skip to content

Instantly share code, notes, and snippets.

@nomadme
Last active May 4, 2023 04:23
Show Gist options
  • Save nomadme/6020d165b43cad4bed87b6941fb44e5d to your computer and use it in GitHub Desktop.
Save nomadme/6020d165b43cad4bed87b6941fb44e5d to your computer and use it in GitHub Desktop.

Simplify Your Pipeline with Archive Artifacts in Jenkins Scripted Pipeline

Jenkins Scripted Pipeline is a popular tool for defining complex build and deployment workflows. A critical step in any CI/CD pipeline is generating and archiving artifacts, which can include binaries, libraries, configuration files, and other artifacts necessary for deploying the application. In this article, we will focus on using the Archive Artifacts function in a Jenkins Scripted Pipeline and how it can help simplify your pipeline.

What is Archive Artifacts?

The Archive Artifacts function is a built-in feature in Jenkins that allows you to archive artifacts produced during a build process. Archiving artifacts can be used for a variety of purposes, such as:

  • Storing the artifacts for future reference
  • Distributing the artifacts to other teams or stakeholders
  • Deploying the artifacts to different environments

By archiving artifacts in Jenkins, you can speed up your development cycle, reduce errors, and ensure consistency in your deployments.

How to Use Archive Artifacts in Jenkins Scripted Pipeline

Using Archive Artifacts in Jenkins Scripted Pipeline is straightforward. Here are the steps you need to follow:

Step 1: Define the Jenkins Scripted Pipeline

First, you need to define your Jenkins Scripted Pipeline to generate artifacts. This can be done using various build tools such as Maven, Gradle, or Ant. Here's an example using Maven:

node {
    stage('Build') {
        // Build the project using Maven
        sh "mvn clean install"
    }

    stage('Archive') {
        // Archive artifacts
        archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
    }
}

This pipeline will first build the project using Maven, then archive all JAR files in the target directory and create a fingerprint for each artifact.

Step 2: Access the Artifacts

After archiving the artifacts, you can access them by navigating to the job's build history page and clicking on the Artifacts link. This will display a list of all the artifacts generated by the job, and you can download them from there.

Conclusion

Using the Archive Artifacts function in Jenkins Scripted Pipeline can help simplify your pipeline and make it more efficient. By following the steps outlined in this article, you can generate and archive artifacts with ease, making it easier to distribute and deploy your application. With the ability to automate these processes, you can speed up your development cycle, reduce errors, and ensure consistency in your deployments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment