1

My task is to pull code from Bitbucket and check whether there are any new files commited or any files modified from last commit. If any chamges are available I need to copy the file name and path to a .csv files. Below commmand will check the diff and copy to .csv files. But same activity needs to happen via Jenkinsfile pipeline.

git diff --name-only --diff-filter=M @~ > list.csv

Jenkinsfile script:-

#!groovy
void Download_Repositories(){
      checkout([
        $class: 'GitSCM', branches: [[name: '*/master']],
        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'code']],
        userRemoteConfigs: [[url: '[email protected]:org-dev/master.git',
        credentialsId:'service-user']]
      ])
}
pipeline {
    agent { label 'LABEL' }
//    triggers { pollSCM('*/5 * * * *') }
  stages {
      stage('Download Repositories') {
        steps {
            Download_Repositories()
            sh '''
            ls -ltr code/playbooks/
            git diff --name-only --diff-filter=M @~ > list.csv
            '''
          }
        }

   }//stages
}//pipeline

Error:-

usage: git diff [--no-index] <path> <path>

1 Answer 1

1

you are doing checkout in code directory so you need to use code directory as your working directory. By default all steps are running into project workspace.

You can use dir to change the working directory see below example:

steps{
    Download_Repositories()
    dir("${WORKSPACE}/code"){
        sh '''
            ls -ltr code/playbooks/
            git diff --name-only --diff-filter=M @~ > list.csv
            '''
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I am getting below error:- git diff --name-only --diff-filter=M @~ fatal: ambiguous argument '@~': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.