Promote Jar file from Snapshot to Release - jenkins

My user is receving the following error when promoting a JAR file from snapshot repository to release repository using artifactory promotion plugin. Please help on how to avoid this error.
Performing dry run promotion (no changes are made during dry run) ...
ERROR: Promotion failed during dry run (no change in Artifactory was done): HTTP/1.1 400 Bad Request
{
"messages" : [ {
"level" : "ERROR",
"message" : "The repository 'XXXXXX' rejected the path 'XX/XX/XXXXX/XX/XXXX/2.1-SNAPSHOT/malin-modular-2.1-20180125.094354-1.jar' due to a conflict with its snapshot/release handling policy."
}, {
"level" : "INFO",
"message" : "Skipping promotion status update: item promotion was completed with errors and warnings."
} ]
}

Little information to guess the reason but assuming this is with Maven repositories...
Each repository is configured to receive either:
only snapshots (i.e. version ends with "-SNAPSHOT" or a timestamp)
only releases (any version except if it ends with "-SNAPSHOT" or a timestamp)
both snapshots and releases (any version is accepted, I don't really recommend this)
This is configured in the details of the local repository, see this page
When you configure your promotion, you configure a move from a repository to another, but you still have to respect the capabilities of your repositories.
So my guess is that you are trying to promote a snapshot version to a repository that only accepts release versions
I suggest you that you set up
a snapshot local repository (e.g. 'dev')
a release local repository (e.g. 'release')
a release local repository for promoted element (e.g. 'gold')
And use
'dev' to push the results of your continuous build on your CI
'release' to push the results of your release process on your CI
'gold' as the target of your promotion process from 'release' to 'gold'

Related

Azure-DevOps - Git Commit Status

We use Jenkins for Build Automation and Azure DevOps for git repository.
For testing purpose, I manually make job failed on jenkins to push failed status.
Then make normal run, and succeed status pushed to Azure DevOps.
But as you see on picture, overall commit status remains as failed.
Rest API that I've used is
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/statuses/create?view=azure-devops-rest-7.0&tabs=HTTP
HTTP Post request sample to Azure DevOps server is:
{
"state": "failed",
"description": "The build is successful",
"targetUrl": "https://myjenkins-server/job/demo-repo/job/demo-branch/7/",
"context": {
"name": "build#34",
"genre": "CI"
}
As you see, buildnumber 21 failed, but #22 and #23 is succeeded. And overall status remains failed.
What can be issue for this?
HTTP Api version is api-version=7.0
Azure DevOps cloud based.
Update:
If I re-run Jenkins job after failed status, it creates job and targetUrl changed, because of new job ID, so new Azure DevOps git commit status created.
I should not do unique targetURL
or
How to remove previous commit status ?
Please note: the overall status of the repository branch will show as succeeded only if the status of all build pipelines is succeeded.

I can't use push_to_git_remote() in fastlane

I have an issue with gitlab, gitlab-ci and fastlane. In fastlane, I am using :
def increment_build_and_commit
incrementBuildNumber()
commit_version_bump(message: 'build number bump [skip ci]')
push_to_git_remote(
remote: 'origin_rw',
remote_branch: ENV['CI_COMMIT_BRANCH']
)
end
So I want to increase build number and commit. So it does the job with:
incrementBuildNumber(),
commit_version_bump(message: 'build number bump [skip ci]')
But when running, it fails at push_to_git_remote
[!] Exit status of command 'git push origin_rw HEAD:HEAD --tags
--set-upstream' was 1 instead of 0. error: The destination you provided is not a full refname (i.e., starting with "refs/"). We
tried to guess what you meant by:
Looking for a ref that matches 'HEAD' on the remote side.
Checking if the being pushed ('HEAD') is a ref in "refs/{heads,tags}/". If so we add a corresponding
refs/{heads,tags}/ prefix on the remote side. Neither worked, so we
gave up. You must fully qualify the ref. hint: The part of the
refspec is a commit object. hint: Did you mean to create a new branch
by pushing to hint: 'HEAD:refs/heads/HEAD'? error: failed to push
some refs to '**********.git'
Some of you have any clues what to do and how to solve this problem? As I am going to be a google machine on that, but unfortunetly can't find the solution.
Thanks in advance!!
This happens because gitlab-ci checkouts git commit instead of git branch and you enter detached HEAD state.
There are few ways to get around this:
1) Use CI provided value. For GitLab I would recommend using CI_PIPELINE_IID. Downside is that you cannot control it and if you migrate your project to other repository it will start from 1 again.
2) Checkout git branch before making commit. Downside is that if other developer pushes to the same branch, your pipeline will continue with wrong source code.
3) Commit version number bump manually.

Difference between $TRAVIS_EVENT_TYPE != 'pull_request' and $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG

I am trying to set up Chromatic in Travis.
I saw Chromatic document recommends using this script in Travis
if [[ $TRAVIS_EVENT_TYPE != 'pull_request' || $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG ]];
then
npm run chromatic
fi
with explanation
Travis offers two type of builds for commits on pull requests: so
called pr and push builds. It only makes sense to run Chromatic once
per PR, so we suggest disabling Chromatic on pr builds for internal
PRs (i.e. PRs that aren’t from forks). You should make sure that you
have push builds turned on, and add the following code: [[THE CODE ABOVE]]
For external PRs (PRs from forks of your repo), the above code will
ensure Chromatic does run on the pr build, because Travis does not
trigger push builds in such cases.
Note: We recommend running Chromatic on push builds as pr builds can't
always run and fall out of the normal git ancestry. For instance, if
you change the base branch of a PR, you may find that you need to
re-approve changes as some history may be lost.
Chromatic does work with Travis pr builds however!
Then I read the Travis document about TRAVIS_PULL_REQUEST_SLUG and TRAVIS_REPO_SLUG.
TRAVIS_PULL_REQUEST_SLUG:
if the current job is a pull request, the slug (in the form
owner_name/repo_name) of the repository from which the PR originated.
if the current job is a push build, this variable is empty ("").
TRAVIS_REPO_SLUG:
The slug (in form: owner_name/repo_name) of the repository currently being built.
So my understanding is when $TRAVIS_PULL_REQUEST_SLUG != $TRAVIS_REPO_SLUG, it is a push build, then why it still needs $TRAVIS_EVENT_TYPE != 'pull_request'?
Is there any difference between them?
Gert from Chroma here.
We recommend to run chromatic only when a build does not originate from a pull request (i.e. a push build), OR when it is a pull request build originating from a fork, in which case the PR slug differs from the repo slug.
Based on the quoted Travis docs, in case of a push build, TRAVIS_PULL_REQUEST_SLUG is empty, in case of a PR build from a fork, it will reference the fork's repo owner. In either case it will be different from TRAVIS_REPO_SLUG. So you're correct that the left-hand side of this condition is superfluous. Feel free to omit it.

Jenkins Artifactory Plug-in

I am new to Artifactory so I apologize if this question has already been answered. I am using rtPromote to Promote Artifactory from one repo (dev) to another repo (qa). Both dry run and performing promotion completes successful. However, when I check the repo the file wasn't copied over. See snippet below.
Am I missing something with rtPromote or do I need to use something different than rtPromote with Jenkins Atrifactory Plug-in? Thank you in advance.
Performing dry run promotion (no changes are made during dry run)
{
"messages" : [ ]
}
Dry run finished successfully.
Performing promotion
{
"messages" : [ ]
}
Promotion completed successfully!

How to check if a pipeline is triggered from a pull request

I'm using Jenkins pipeline to build Pull Requests branches using the GitHub Organization plugin.
I can build them fine, but I want to avoid some steps (such as publishing the artifacts). Checking git's current branch gives me the PR's target since the PR branch is being merged into the target before the build is attempted.
How can I check if the build is being initiated from a PR vs than a regular branch build?
At least on Jenkins 2.16 env.BRANCH_NAME gives the source branch not the target branch. You could do something like:
if (env.BRANCH_NAME == "master") {
sh "./publish.sh"
}
Other env vars that could be useful are the CHANGE_* variables. E.g.,
CHANGE_AUTHOR='me'
CHANGE_ID='6'
CHANGE_TARGET='master'
CHANGE_TITLE='Update README.md'
CHANGE_URL='https://github.com/test-org/test-repo/pull/6'
For documentation on these and more: https://ci.eclipse.org/webtools/env-vars.html/
The env variable CHANGE_ID only exists when the build is triggered from a Pull Request check.
For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.
To specifically detect GitHub pull requests, this can be used:
script {
if (env.BRANCH_NAME == 'master') {
sh 'make'
} else if (env.BRANCH_NAME.startsWith('PR')) {
// do actions for pull request
} else {
// some other branch
}
}
Of course, if you expect to have branches starting with PR on your main repository this wouldn't be reliable. The nice thing about it is that script can be used also in post not just stages, which is useful since when is not allowed in post. If you don't care about that it's worth looking into the when directive. There is some documentation from Cloudbees and Jenkins with some examples.

Resources