1
votes

I have a Jenkins pipeline. Every time I check into git, I need to access the changed files (or all files in a particular directory) and upload them into my Azure Storage account.

I'm able to upload files into the storage account using Azure CLI but I'm unable to access the git files. When I try to use the following in my JenkinsFile, I get null and null for both values.

echo "The commit hash is ${env.GIT_COMMIT} ${env.GIT_PREVIOUS_SUCCESSFUL_COMMIT}"

Given my use case, what should be my best approach? Is there any way I can access the files so that I can upload them?

My Jenkins version - 2.214.

1

1 Answers

0
votes

In your pipeline, if you are trying to echo valid ${env.GIT_xxxx} directly without obtaining and saving the Map returned by checkout then I believe you can try to obtain the Map returned by checkout and save the Map as environment variable.

stage('Checkout code') {
  steps {
    script {
      // Checkout the repository and save the resulting metadata
      def scmVars = checkout([
        $class: 'GitSCM',
        ...
      ])

      // Display the variable using scmVars
      echo "scmVars.GIT_COMMIT"
      echo "${scmVars.GIT_COMMIT}"

      // Displaying the variables saving it as environment variable
      env.GIT_COMMIT = scmVars.GIT_COMMIT
      echo "env.GIT_COMMIT"
      echo "${env.GIT_COMMIT}"
    }

    // Here the metadata is available as environment variable
    ...
  }
}

Just FYI, this is the source of the above information. Hope this helps!