No commits are visible under pipeline run, thus affectedFiles list is empty, when using "git commit --amend" and "git push --force"
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'LocalBranch'], [$class: 'CleanCheckout']],
userRemoteConfigs: scm.userRemoteConfigs,
])
Related
I have following code:
skipDefaultCheckout()
(...)
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
How do I debug the execution of this? I am hitting
fatal: not a git repository (or any of the parent directories): .git
error, but I don't know why. Any hints Guys? Is it possible to print out values of variables of this class? For example: scm.branches?
I have my Jenkinsfile located in repo "A" and I was to checkout a repo in repo "B". What's the correct way to do that?
This is how I have currently doing it, but it's not working:
stage("Checkout my repo repo ") {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'copy-repo-here']],
userRemoteConfigs: [[credentialsId: 'my-creds',
url: 'git#github.com:my-git-repo.git']]])
}
}
Any help is appreciated!
I was fixing a pipeline which was written for mercurial scm and there I found an installation parameter how would I give the same parameter to the git scm.
checkout([$class: 'MercurialSCM',
credentialsId: '',
installation: 'HG-3.4',
source: 'https://',
clean: true,
revision: branch,`branch`
browser: [$class: 'BitBucket', url: 'https://']])
checkout([$class: 'GitSCM',
branches: [[name: '${branch}']], browser: [$class: 'BitbucketWeb', repoUrl: 'https://'],
extensions: [[$class: 'CleanBeforeCheckout']],
userRemoteConfigs: [[credentialsId: 'creds',
url: 'https://']]])
I am trying to pull a specific tag from two different repos in my Jenkinsfile. The tags are determined by getting the latest successful builds from the relevant pipeline and using these values to decide which tag to checkout. However I am getting issues as SCM is not replacing the withEnv variables I have added. In the code below you can see I am echoing out what should be the tag (and this echo works fine) but when it comes to SCM checking out the tag LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD and LAST_SUCCESSFUL_SHARED_REPO_BUILD variables are no substituted with their values
node {
stage('Checkout') {
withEnv([
"LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD=${ sh ( script: "curl <JENKINS_URL>/job/extensionsrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true ) }",
"LAST_SUCCESSFUL_SHARED_REPO_BUILD=${ sh ( script: "curl <JENKINS_URL>/job/sharedrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true ) }"
]) {
sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}'
sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}'
checkout scm
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/extensions'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/shared'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])
}
}
// test, stage, deploy
}
Any pointers on what I am doing wrong here would be much appreciated. No doubt it is something stupid that I am failing to do correctly.
Thanks
Try replacing the single quotes in your checkout call where you have the branch var with double quotes. In general, in Groovy you should use double quotes when including embedded variables (see What's the difference of strings within single or double quotes in groovy?).
Like:
checkout([
$class: 'GitSCM',
branches: [[name: "refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/extensions'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])
With the Jenkins Workflow Plugin, I can checkout a repository based on branch. However, I would like to checkout a repository based on a tag.
This is my current configuration for checking out the master branch
node {
git url: src, branch: 'master'
}
Now I would like to achieve to check out tag 3.6.1. I tried to change the branch to a tag, but that won't work. Neither is there something in the documentation regarding checking out on tag.
Is this currently possible? Am I overseeing something?
references;
https://github.com/jenkinsci/workflow-plugin
https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/README.md
https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/src/main/resources/org/jenkinsci/plugins/workflow/steps/scm/GitStep/config.jelly
https://github.com/jenkinsci/workflow-plugin/blob/master/scm-step/src/main/java/org/jenkinsci/plugins/workflow/steps/scm/GitStep.java
Just found the answer myself by crawling through the issue list. Seems like they won't change it; https://issues.jenkins-ci.org/browse/JENKINS-27018
This is the suggested solution;
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: src]], branches: [[name: 'refs/tags/3.6.1']]], poll: false
This works:
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL,
credentialsId: credential]], branches: [[name: tag-version]]],poll: false
Not This:
checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repoURL],
[credentialsId: credential]], branches: [[name: tag-version]]],poll: false
noTags: false does the trick.
checkout([$class: 'GitSCM', branches: [[name: githash ]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CloneOption',
depth: 0,
noTags: false,