Certified Jenkins Engineer

Jenkins Administration and Monitoring Part 1

Demo Jenkins Folder Part 3

In this guide, you’ll learn how to clone an existing Jenkins folder configuration—team-a—to a new folder named team-c. By copying the folder, Team C automatically inherits pipelines, credentials, and settings from Team A, ensuring consistency and reducing setup time.

Table of Contents

  1. Creating the Team C Folder
  2. Verifying the Copied Pipelines
  3. Accessing Inherited Credentials
  4. Triggering and Viewing the Build
  5. Sample Console Output
  6. References

Creating the Team C Folder

  1. In Jenkins, click New Item.
  2. Enter team-c for the folder name.
  3. Select Folder as the item type.
  4. Under Copy from, search for and choose team-a.
  5. Click OK to confirm.

The image shows a Jenkins interface for creating a new item, with options like "Multi-configuration project," "Folder," "Multibranch Pipeline," and "Organization Folder." There's also a field to copy from an existing item.

Jenkins will replicate all projects, credentials, and folder-level settings from team-a into team-c.

Note

Copied folder items (jobs) inherit the disabled state. You must manually enable them before running builds.


Verifying the Copied Pipelines

Navigate into the newly created team-c folder. You should see team-a-pipeline listed—this confirms the pipeline configuration has been cloned successfully.

The image shows a Jenkins dashboard interface with a project named "team-c" and a pipeline labeled "team-a-pipeline." It displays options for configuration, build history, and other project management features.

Open the pipeline’s Configure view and compare it to Team A’s pipeline to ensure all stages and steps match.


Accessing Inherited Credentials

Since team-c inherits from team-a, it also has access to both the Shared Infrastructure credentials and the Team A credentials. Verify under Credentialsteam-cshared-infrastructure.

The image shows a Jenkins credentials management page for a project named "shared-infrastructure" under "team-c," displaying various credential stores and their domains.

In your Jenkinsfile, use a withCredentials block to bind these credentials to environment variables:

pipeline {
    agent any
    stages {
        stage('Accessing Credentials') {
            steps {
                withCredentials([
                    usernamePassword(
                        credentialsId: 'shared-db-creds-id',
                        usernameVariable: 'SHARED_DB_USR',
                        passwordVariable: 'SHARED_DB_PSW'
                    ),
                    usernamePassword(
                        credentialsId: 'team-a-creds-id',
                        usernameVariable: 'TEAM_A_USR',
                        passwordVariable: 'TEAM_A_PSW'
                    )
                ]) {
                    script {
                        echo "Shared DB Username: ${SHARED_DB_USR}"
                        echo "Team A Username: ${TEAM_A_USR}"
                    }
                }
            }
        }
    }
    post {
        success { echo "Build completed successfully" }
        failure { echo "Build failed" }
    }
}

Credentials Reference Table

Credential IDBound VariablesPurpose
shared-db-creds-idSHARED_DB_USR<br>SHARED_DB_PSWShared infrastructure database access
team-a-creds-idTEAM_A_USR<br>TEAM_A_PSWTeam A-specific secrets

Triggering and Viewing the Build

  1. Inside team-c, open team-a-pipelineConfigure and click Save to enable the job.
  2. Click Build Now on the pipeline page.
  3. Monitor the progress: each stage, including “Start,” “Accessing Credentials,” and “Post Actions,” should complete successfully.

The image shows a Jenkins dashboard displaying the status of a pipeline named "team-a-pipeline," with stages like "Start," "Accessing Credentials," and "Post Actions" marked as completed. The sidebar includes options like "Build Now," "Configure," and "Open Blue Ocean."


Sample Console Output

Started by user siddharth
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/shared-infrastructure/team-c/team-a-pipeline
[Pipeline] withCredentials
Masking supported pattern matches of $TEAM_A_USR or $TEAM_A_PSW or $SHARED_DB_USR or $SHARED_DB_PSW
[Pipeline] stage
[Pipeline] { (Accessing Credentials)
[Pipeline] script
[Pipeline] echo
Shared DB Username: shared-DATABASE-username
[Pipeline] echo
Team A Username: team-AAAAA-username
[Pipeline] }
[Pipeline] // script
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Build completed successfully
[Pipeline] }

By cloning team-a into team-c, you ensure all pipelines, credentials, and folder-level configurations are inherited, streamlining setup for new teams and maintaining organizational standards.


References

Watch Video

Watch video content

Previous
Demo Jenkins Folder Part 2