Skip to content

Jenkins

Ramkumar edited this page May 24, 2022 · 5 revisions

Usage of Security Credentials plugin (withCredentials) in Pipeline Jobs:

Reference: https://www.jenkins.io/doc/pipeline/steps/credentials-binding/

  • Credential of type/kind: Token
  stage("Create Docker image") {
      steps {
      withCredentials([string(credentialsId: 'ram-dockerhub-login', variable: 'TOKEN')]) {
      
              sh '''
                sudo docker build -t oshokumar/appointme-admin-api:latest .
                sudo docker login -u oshokumar -p ${TOKEN}
                sudo docker push oshokumar/appointme-admin-api:latest
                
                '''
		}
            }

Here, the Global credential of kind/type "Secret Text" is used to provide credentials to the Docker login in the above example.

  • Credential of type/kind: "Username with Password":
stage("Docker build & push") {
            steps {
              withCredentials([usernamePassword(credentialsId: 'nexus-secret', passwordVariable: 'pass', usernameVariable: 'user')]) {
                sh """ 
                  
                  sudo docker build -t 34.122.223.20:8082/appoint-api:${BUILD_NUMBER} .
                  sudo docker login  -u ${user} -p ${pass} 34.122.223.20:8082
                  sudo docker push 34.122.223.20:8082/appoint-api:${BUILD_NUMBER}
                """
              }              
            }
          } 

Here, it uses the credential of type/kind as "Username with Password" and the required parameters are passed accordingly to the plugin "withCredentials".

  • Credential of type/kind: "File"
node {
  withCredentials([file(credentialsId: 'secret', variable: 'FILE')]) {
    dir('subdir') {
      sh 'use $FILE'
    }
  }
}

====

Issues with Nexus Repository Manager.

Error with the pipeline job:

received unexpected HTTP status: 500 Server Error

The nexus.log showed the below error which was due to lack of space where the database files of Nexus have been and fixed the issue by resizing the filesystem.

2022-05-19 16:42:01,317+0000 WARN  [qtp1481478392-95]  admin org.sonatype.nexus.repository.docker.internal.V2Handlers - Error: PUT /v2/appointme-admin-api/blobs/uploads/cc1c594e-eadd-4d91-a113-7d9dcbf0800a
com.orientechnologies.orient.core.exception.OLowDiskSpaceException: Error occurred while executing a write operation to database 'component' due to limited free space on the disk (2237 MB). The database is now working in read-only mode. Please close the database (or stop OrientDB), make room on your hard drive and then reopen the database. The minimal required space is 4096 MB. Required space is now set to 4096MB (you can change it by setting parameter storage.diskCache.diskFreeSpaceLimit) .^M
        DB name="component"
Clone this wiki locally