env.serviceName = 'salesautomat-connector-plugin'
params.versionNumber
lock(resource: "${env.JOB_NAME}_${env.BRANCH_NAME}", inversePrecedence: false) {
    node('linux') {
        deleteDir()
        stage('Checkout from SCM') {
            dir('git') {
                checkout([$class: 'GitSCM', localBranch:'', branches: [[name: 'refs/heads/'+BRANCH_NAME ]], doGenerateSubmoduleConfigurations: false, userRemoteConfigs: [[credentialsId: 'github_admin_ffoperations', name: 'origin', url: 'https://github.com/FLOWFACTCorp/'+serviceName+'.git', refspec: '+refs/heads/' + BRANCH_NAME + ':refs/remotes/origin/' + BRANCH_NAME]]])
            }
        }
        stage('Tag in git') {
            dir ('git') {
                withCredentials([[$class          : 'UsernamePasswordMultiBinding', credentialsId: 'github_admin_ffoperations',
							  usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
                    sh "git remote set-url origin https://${USERNAME}:${PASSWORD}@github.com/FLOWFACTCorp/${serviceName}.git"
                    sh "git checkout -b master origin/master"
                    sh "git pull"
                    sh "git tag ${params.versionNumber}"
                    sh "git push -u origin master"
			
                }}}
        stage('Copy files') {
            fileOperations([folderCopyOperation(destinationFolderPath: 'svn', sourceFolderPath: 'git')])
        }
        stage('Tag in svn') {
            dir('svn') {      
                withCredentials([[$class          : 'UsernamePasswordMultiBinding', credentialsId: 'github_admin_ffoperations',
							  usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
                    sh("svn checkout --username ${USERNAME} --password ${PASSWORD} svn://10.5.29.221/home/user/salesautomat-flowfact-connector")
                    sh("svn add --force *")
                    sh("svn commit * -m '${params.versionNumber}'")
                }      
                //sh("svn copy http://10.5.29.221/repos/calc/trunk http://svn.example.com/repos/calc/tags/release-1.0 -m ''")
            }
        }
    }
}