airdata
airdata

Reputation: 641

Jenkins build output set as current build description

I want to set current build description in my jenkins job from #bash output

Jenkins build output set as current build description

For example to set revision and branch from string and choice parameters I do it like this:

   parameters {
       string(defaultValue: "", description: '11.00', name: 'REVISION')
       choice(name: 'BRANCH', choices: 'trunk\nupdate', description: 'Branch')
   }

   stage('Set build') {
      steps {
         script {
             // Set build parameters
             currentBuild.description = "$REVISION $BRANCH"
         }
      }
   }

Let's say that I want get my diskspace % #bash execution and put it in the description...

   stage('bash') {
      steps {
         script {
         sh '''
            DISK_SIZE="$(df -h --output='pcent' /mnt | grep -v "Use%")
         }
        currentBuild.description = "$DISK_SIZE"
      }
   }

I want in the build description for example to put my disk%. In this case I expect to in the description %30

Or to put some other staff that are generated from current build.

Upvotes: 1

Views: 2366

Answers (1)

kirkpatt
kirkpatt

Reputation: 623

You can tell your sh command to return its stdout using the returnStdout option.

myOutput = sh(script: '$(df -h --output='pcent' /mnt | grep -v "Use%")', returnStdout: true)

currentBuild.description = myOutput

Upvotes: 2

Related Questions