required to copy properties file from GIT and place them in NASPATH using jenkins

Viewed 287

Required to copy/clone/fetch files from GIT and place them to NASPATH(Unix server) using Jenkins Job. Does any has done this earlier ?

2 Answers

With a plugin like Custom workspace path, you could define the path where the Jenkins pipeline does checkout your repository, using the path you need.

For instance, a file mount on a remote NAS device, as mentioned in JENKINS-48435

Using pipelines, you can do any git action and file copying to any location accessible by jenkins. A declarative pipeline to do this could look like this:

pipeline {
    agent any
    environment {
        source_repo = 'https://your.repo/sitory.git'
        source_path = 'path/of/file/in/repo'
        target_path = '/location/to/nas'
    }
    stages {
        // checkout
        stage ("checkout") {
            steps {
                git url: source_repo
            }
        }
        stage ("copy") {
            steps {
                sh 'cp $source_path $target_path'
            }
        }
    }
}

This is obviously simplyified and onyl a proof of concept, as you did only provide a basic idea of what you want to achieve with some details missing. More below.

Notes:

  • the sh step ist only availabe on linux servers, and so is, obviously cp. On windows, use a bat step with copy instead.
  • if your git needs authentication, use the credentialsId parameter of the git pipeline step
  • if you want another branch but master, use the branch parameter of the git pipeline step
  • if you need top copy the entire git directory, or more than one file, adjust the environment variables and copy command accordingly.
Related