To pass Artifactory credentials to Gradle in a Jenkins Pipeline job, you can use the Jenkins Artifactory Plugin and the Jenkins Credentials Plugin. The Artifactory plugin integrates Artifactory repositories with Jenkins, allowing you to resolve and deploy artifacts during your build process.

Here's a step-by-step guide with an example of how to pass Artifactory credentials to Gradle in a Jenkins Pipeline job:

Step 1: Install the required plugins
Install the Jenkins Artifactory Plugin and the Jenkins Credentials Plugin if you haven't already. You can do this from the Jenkins dashboard by navigating to "Manage Jenkins" > "Manage Plugins" > "Available" and then searching for and installing the plugins.

Step 2: Set up Artifactory credentials
1. Navigate to "Jenkins" > "Manage Jenkins" > "Manage Credentials."
2. Click on "Jenkins" (or "Global") and then "Add Credentials."
3. Choose the "Username with password" option.
4. Enter your Artifactory username and password.
5. Optionally, you can set an ID for these credentials (e.g., "artifact-creds") to use it later in the pipeline script.

Step 3: Create a Jenkins Pipeline job
1. Go to the Jenkins dashboard and click on "New Item."
2. Enter a name for your pipeline job and select "Pipeline" as the job type.
3. Scroll down and find the "Pipeline" section.

Step 4: Define the Jenkins Pipeline script
In this example, we'll use a scripted Jenkins Pipeline, but you can adapt it for a declarative pipeline if needed.

pipeline {
    agent any

    environment {
        // You can set other environment variables here if needed

    stages {
        stage('Checkout') {
            steps {
                // This stage checks out your code from version control (e.g., Git)
                // Add your SCM checkout step here

        stage('Build') {
            steps {
                // This stage executes the Gradle build using Artifactory credentials
                // The credentials are passed as environment variables to Gradle

              script {
                    def artifactoryCreds = credentials('artifact-creds')
                    withCredentials([usernamePassword(credentialsId: artifactoryCreds, usernameVariable: 'USER_1', passwordVariable: 'PSWD_1')]) {
                        // Execute your Gradle build here, passing the credentials as environment variables
                        sh './gradlew build -Partifactory_user=${env.USER_1} -Partifactory_password=${env.PSWD_1}'

        // Add more stages as needed for your pipeline


1. In the environment block, you can set other environment variables needed for your build, if any.

2. In the Build stage, we use the credentials function from Jenkins to access the Artifactory credentials previously configured in Jenkins.

3. We then use the withCredentials block to mask the credentials during execution.

4. Inside the withCredentials block, we execute the Gradle build using sh (Shell script), passing the Artifactory username and password as environment variables (USER_1 and PSWD_1, respectively)to Gradle.

5. Replace './gradlew build' with your actual Gradle build command, and adjust the options and tasks as needed for your specific project.

That's it! This pipeline script will now run your Gradle build with the provided Artifactory credentials in a Jenkins Pipeline job.