Log in on OpenShift using Jenkins - jenkins

I have a docker container with jenkins deployed using OpenShift Origin.
Now I want to use Jenkins to build/test and deploy other OpenShift apps.
So I try to login on my OpenShift-server (from inside my jenkins) but than I get the following error. Can someone help me?
Started by user Jenkins Admin
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jobs/s2i-build-deploy/workspace
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
APP_HOSTNAME=http://test.apps.example.com
USER_NAME=admin
PASSWORD=admin
OSO_SERVER=ip.compute.internal:8443
DEVEL_PROJ_NAME=test
SERVICE=test
[EnvInject] - Variables injected successfully.
[workspace] $ /bin/sh -xe /tmp/hudson1352752763797328747.sh
+ oc login -uadmin -padmin --server=ip.compute.internal:8443
error: x509: certificate signed by unknown authority
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The oc login-command is working when I'm performing directly in my server.

That error means you need to also specify the CA that was used to sign the API server's certificate. You will need to also specify --ca-file (check oc help options) with the ca.crt of the master in order to login.

As mentioned in this comment try:
oc login $OPENSHIFT_URL --insecure-skip-tls-verify=true

Related

Not able to build jenkins pipeline

[EnvInject] - Loading node environment variables.
Building remotely on Dox2u_DockerRegistry in workspace /home/admin-vm/workspace/(Handler)(Document_Handler)(release_1.0.0.1)(dochandler_UAT)
[(Handler)(Document_Handler)(release_1.0.0.1)(dochandler_UAT)] $ /bin/sh -xe /tmp/jenkins6559820756424608510.sh
export BRANCH_NAME=release_1.0.0.1
/home/admin-vm/Data/workspace/Docker_Project/./pullcode_uat.sh
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Already on 'release/1.0.0.1'
Your branch is up to date with 'origin/release/1.0.0.1'.
Host key verification failed.
fatal: Could not read from remote repository.
I am trying to build project

Jennkins not able to connect AWS Account

I have Jenkins file to deploy my application into EKS cluster. From jenkins side i installed AWS credential plugin and I added Jenkins credential my secret key and access key values into the box.
Next when I'm running Jenkins build deployment stage falling with below error .
Unable to connect to the server: getting credentials: exec: executable aws not found
It looks like you are trying to use a client-go credential plugin that is not installed.
I faced similar issue and found it was a PATH settings issue. Basically aws is not found in PATH . What you could do is add "env" to the code and see what PATH values are in console output. To set the PATH correctly
Manage Jenkins -> Configure System -> Global properties -> Environment variables: name=PATH, value= (Ex: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/ )

Unable to run command to remote machine via Jenkins

While trying to execute some shell command to a remote server from Jenkins, I am getting "Host key verification failed." error.
I have installed Jenkins in a docker on my MAC. Now from the Jenkins browser, I want to run some shell command to a remote server (which is accessible).
To do that I already added the server (10.206.y.z) in the configure page of jenkins (by providing hostname i.e. 10.206.y.z, username & the key generated in 10.206.y.z server in the SSH Servers section) & tested the connection. The connection test passed & then I saved the configuration.
For executing shell command on 10.206.y.z, I created a FreeStyle project & in the Execute Shell section I am passing ssh root1#10.206.y.z 'hostname'.
If I run the project by clicking 'Build Now', I am getting the below error & the build fails.
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/TestProject
[TestProject] $ /bin/sh -xe /tmp/jenkins4234161871485451783.sh
+ ssh root1#10.206.y.z hostname
Host key verification failed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Any help please?
I think that the problem is the key. You are using the key generated in the destination machine (10.206.y.z)
You should use the key generated on the jenkins server and pass it to the destination server. For that you could use ssh-copy-id

terraform error can some body help me out of this but iam providing valid tokens in the keys file

terraform plan -var-file=uservar.tfvars
[0m[1mRefreshing Terraform state in-memory prior to plan...[0m
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
[0m
[31mError refreshing state: 1 error(s) occurred:
* provider.aws: InvalidClientTokenId: The security token included in the request is invalid.
status code: 403, request id: 39888d7e-b3f1-11e7-b6d2-9b6dc0727868[0m[0m
Build step 'Execute shell' marked build as failure
Finished: FAILURE
You need to run terraform init first, then terraform plan
Go through this document first: terraform Command: init
Secondly, for error The security token included in the request is invalid., please go through aws configuration to make sure you have set the AWS security token properly.
I got resolution for this one.
Do you pull your code form Git? If yes, pull only once
Note: Code on Git does not have access_key and secret_key, so if your jenkins job contains source control for every build the values (access_key and secret_key) are overridden.
-> Pull the code only once
-> In your jenkins/workspaces, set your access_key and secret_Key (or you can also mention it in Jenkins Build)
Before executing Jenkins job, Set aws cli parameters
aws configure
Set access_key, secret_key & region
and then execute
terraform init
terraform plan -var-file=uservar.tfvars

Passing client IP information to Jenkins Job

In Jenkins, I want to pass the ip of the client that initiated the build to the Jenkins job so I can access that information inside a class that extends "Builder" or as an environment variable, or anything that works.
So for example, in the console log of every build, I can print something like: "Job started by user1 from ip: 10.101.101.1"
I know I can get an audit trial by using the "Audit Trial" plugin for Jenkins, but I would like to print that information to the build console so it'll be more straight forward.
Thanks in advance.
Edit: I want the ip of the user/client that started the job/build, which is not necessarily the ip of the jenkins slave the job is running on.
Jenkins not able to pass the client IP to a variable at the moment , the Client IP you saw at the output log is remote cause message.
I would say it is indeed useful to get remote IP in a job to enable some callback functions . Alternatively you can pass the IP as parameter when make the remote call
echo $ipaddr in your shell script of jenkins job
Enable the string parameters in jenkins job
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
Make the call
curl -k -u user:apitoken -X POST
https://jenkins.local/job/yourjob/build \ --data token=jobtoken \
--data-urlencode json='{"parameter": [{"name":"ipaddr", "value":"x.x.x.x"}]}'
You can use the EnvInject plugin and use the "Prepare an environment for the run" option.
In the "Evaluated Groovy script" section, copy this code:
return [IP_ADDRESS: InetAddress.localHost.canonicalHostName]
Then, you use the $IP_ADDRESS in your build step section.
echo $IP_ADDRESS
Build log:
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Evaluation the following Groovy script content:
return [IP_ADDRESS: InetAddress.localHost.canonicalHostName]
[EnvInject] - Injecting contributions.
Building on master in workspace /var/lib/jenkins/jobs/Test Groovy IP address/workspace
[workspace] $ /bin/sh -xe /tmp/hudson6447343457570437614.sh
+ echo 172.16.203.72
172.16.203.72
Notifying upstream projects of job completion
Finished: SUCCESS

Resources