SHA Commit number from Pipelinec w/ Openshift Plugin - openshift

I'm using the OpenShift plugin with Jenkins Pipelines to run builds in OpenShift when Github gets a new commit.
I'd also like to be able to report the status of the build back to github.
However in order to do this, I need to know what the commit was that just got built. I'm using the following pipeline config
node() {
stage 'build'
def builder = openshiftBuild(buildConfig: 'my-web', showBuildLogs: 'true')
stage 'deploy'
openshiftDeploy(deploymentConfig: 'my-web')
openshiftScale(deploymentConfig: 'my-web',replicaCount: '3')
}
However I have zero idea how to get the commit SHA from the openshiftBuild step since this does the git pull.

According to https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables, you get it from the GIT_COMMIT environment variable.
If the checkout happens later, you can get it with the following code:
def gitCommitId = sh(returnStdout: true, script: 'git rev-parse HEAD')

It's hard to tell without seeing the rest of your pipeline, but it looks like you are just triggering an OpenShift S2I build, which is not what is recommended for Pipeline builds. You should have your pipeline build the artifact(s) for the application, then use an S2I binary build to have OpenShift put the artifacts into a runtime container. For an example, see HERE.

Related

Failed to pull image "image-registry.openshift-image-registry.svc:5000/..." OpenShift CRC

I am trying to install a sample application using the git option in OpenShift 4.7.2 (CodeReady containers 1.24) and I keep getting the below error while openshift tries to build the image to be deployed.
Failed to pull image
"image-registry.openshift-image-registry.svc:5000/employee-ecosys/person-service:latest": rpc error:
code = Unknown
desc = Error reading manifest latest in image-registry.openshift-image-registry.svc:5000/employee-ecosys/person-service:
manifest unknown: manifest unknown
The application person-service is a simple crud application build using spring-boot and uses in-memory h2 as its database. Github repo is here
Some checks to perform:
Are the image registry pods running?
oc get pods -n openshift-image-registry
Is your specific image created?
oc get images | grep "person-service"
Do you get any images?
oc get images
"latest" is kind of a special tag. You should never manually tag an image as "latest". Openshift will consider the "latest" tag to be the newest image, regardless of what tag it has.
I am not familiar with the git deploy method. I have personally very little experience with any s2i builds. I normally use a git repo for the openshift/kubernetes resources and a git repo for the code (they can be the same but separated in the tree by folder structure) and use a pipeline or manually build the image and push it to a registry somewhere and then let openshift pull it from there.

How to properly update build config / image stream when source code changes in OpenShift?

((I'm still learning; apologize in advance if I may have misunderstood some basics.))
In OpenShift, I have a pipeline that uses oc new-build (sourceCodeGitAddress) and oc start-build to create my deployment. If I rerun the pipeline though, it fails because it says - rightfully so - that there is already a buildConfig and imageStream. Is there a better way for me to run this pipeline so it automatically updates / builds / pushes / etc. to the build config and image stream?
Okay, I think I got it. I think I just need a separate pipeline that just runs the start-build and it will re-pull the source code and deploy. At least, that's what I'm seeing in the logs. Please feel free to correct me!
BuildConfig could be restarted via webhook-triggers configuration or you have to exclude new-build operation from the pipeline.
In addition, 'oc apply' can be rerun idempotently
More about BC start

Polymer web component tester: multiple sauce configurations?

I'm using SauceLabs for my web component tests through the 'sauce' plugin in the web component tester. I'd like to use this plugin with different configurations depending which branch is being built on my CI.
I.E.: Latest chrome only on dev branches, and the whole battery of browsers/OS on master/staging branches (with deploy env.)
How can I achieve that?
Copy a template file before you start wct
// Test master branch
$ cp wct.conf.master.json wct.conf.json && wct
// Test feature branch
$ cp wct.conf.feature.json wct.conf.json && wct
The best way to do so for now remains the cp/mv method as stated in the official answer, but in web-component-tester#v6.0.0-prerelease.8, they included back the --config option (see this commit), so we'll be able to specify which config file to use at runtime without modifying any file.

Get latest revision of the remote repository with javahg

In our current Java project we want to compare the local with the remote revision number of an alreay cloned mercurial repository, especially we want to get the latest revision number from the server. We are using javahg to access mercurial functions. But we can't find any command in the javahg library to achieve that.
Normally, you would use the identity command, but this is not supported in this library. Another way could be to use the incoming command, which is supported, but it seems not to work for us. We tried to execute the following code line:
IncomingCommand.on(localRepo).execute(serverURL)
and the resulting bundle returns "-1". After a quick look into the source code of the execution function we found out that this method operates only on local repositories.
Has anybody an idea how the incoming command could be used to get the latest revision from the remote repository? Or is there another way to do this?
Any help is appreciated. Thanks!
The incoming command downloads a 'bundle file' containing the remote changesets not present locally. From the Bundle instance you can use getOverlayRepository() to get a Repository instance that any other command can be invoked on.
Here's an example of using Incoming with a remote repository:
Repository repoB = ..;
Bundle bundle = IncomingCommand.on(repoB).execute("http://localhost:" + port);
List<Changeset> changesets = bundle.getChangesets();
List<Changeset> heads = bundle.getOverlayRepository().heads();
I'm not sure the precise semantics of 'identify' but maybe a similar effect could be achieved by listing heads of the bundle overlay repository.
Identify seems much more efficient if you're just interested in the node id and not the changes themselves. Feel free to post a feature request here: https://bitbucket.org/aragost/javahg

Can't get build artifacts to display properly in Jenkins/Hudson

I currently Jenkins to as my continuous integration system and I use Gradle to build my project. Without changing anything Gradle by default puts all the build artifacts under the /build folder in the workspace. This obviously doesn't work well since the build artifacts get overwritten by the following build.
I have modified my script to output the files in the /builds/[BUILD_ID] folder on Jenkins, which puts the build artifacts in the correct build folder on the CI system, but they don't show up in the Jenkins gui when you navigate to a specific build.
How do I get my build artifacts to display in Jenkins? Where do they need to be put, in order to show up for each build?
In the Post Build Actions section of your Jenkins job configuration, select "Archive the artifacts" and specify which files to archive. Jenkins will save them with the rest of the build data and provide links to each file on the build page.