How to install a service using Jenkins - jenkins

I would like to install Google cloud SDK as a service with Jenkins through the plugin. But I didn't find the source on how it should be done. Can someone help me out on this?

For installing the Google Clous SDK in a Linux (Ubuntu) environment using Jenkins do the following:
Create a freestyle Jenkins job and in the build step add Execute shell and then add the following script into it:
#create an environment variable for the correct distribution
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
#Add cloud SDK URI to the pacakage source
sudo echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
#Import Google Cloud public key
sudo curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
#Install the SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk
Then run the job, it will install Google Cloud SDK in your machine.
The login to the machine and run sudo gcloud init to get started with the SDK.
For more info follow this documentation.

Related

How to install Docker in Ubuntu offline

I need to install Docker in an Ubuntu 18 machine which do not have any internet access. There are plethora of instruction material exist on this this subject but all they require Ubuntu machine to be online.
Any help on offline installation of Docker will be highly helpful.
Thanks,
On any machine with internet access, do the following:
Go to https://download.docker.com/linux/ubuntu/dists
Choose your Ubuntu distribution (For 18.0.4 it would be beaver/)
Navigate to pool/stable/<processor architecture>
Download the most recent version of each package
After transferring the .deb files to your offline Ubuntu machine/VM:
In a terminal, navigate to the folder which contains your .deb files
Execute dpkg -i <package1> <package2> <package3> in order to install the downloaded packages
Verify that the service is running by switching to /opt/ and executing systemctl status docker.service
After this you should be able to configure your docker installation and import packages via the docker load command
Run these commands:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` test"
sudo apt update
sudo apt install docker-ce

How do I specify a package installation (for Yarn) within a CircleCI docker image?

I am using CircleCI to test a Rails app. I need to run have my images use a later version of Yarn (1.19 currently) than is available off the image we are using for our CI tests (circleci/ruby:2.6-node-browsers).
What is the configuration step/entry in config.yml to do this? I assume I have to run something in the build step that upgrades the Yarn version (which in the image is currently 1.17.) But I can't figure out what it is.
Starting with the Circle docs on Yarn, I tried installing Yarn through that curl command they have in their example (as of Oct '19), which goes:
run:
name: install Yarn
command: curl -o- -L https://yarnpkg.com/install.sh | bash
This did not work - yarn -v still returned 1.17.
I subsequently heard back from CircleCI support, and changed this to:
- run: |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ rc main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
sudo rm /usr/local/bin/yarn && sudo ln -s /usr/bin/yarn /usr/local/bin/yarn
and that worked. I am going to guess it's because the use of sudo sets the global path soft links correctly, and the local install did not. I could possibly have gotten here by resetting the PATH variable but I am pasting this here, because using the apt route seems the "better" solution to me.

How to invoke yarn command in docker's jenkins?

When I install yarn using this command in CentOS terminal:
sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
# Install yarn
yum install -y yarn
The yarn command run perfectly in terminal. But when the run the yarn install command in Docker's Jenkins(after docker's jenkins chekcout the project source code,compile react project),this is my build script:
yarn install
yarn build
it throw this error:
/bin/sh -xe /tmp/jenkins3735067167187767767.sh
+ yarn install
/tmp/jenkins3735067167187767767.sh: 2: /tmp/jenkins3735067167187767767.sh: yarn: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
When I don't using docker,I know it runs as user jenkins,but now I could not switch to user jenkins because it does not have a jenkins user.How to fix it?
Docker version 1.13.1, build 07f3374/1.13.1
Node version:v10.15.3
yarn version:v1.15.2
Your host is isolated from the docker container, so whatever you need to install you have to install inside the container itself not on the actual host. In case you are using an ubuntu image you need to do the following steps inside your container or inside your Dockerfile if you are building your own image. Make sure to use the root user for these steps:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn
If you are just getting started with docker I suggest that you take a look at the following tutorial to get a better view about how it works: https://docs.docker.com/get-started/

Jenkins not connecting on AWS EC2 Ubuntu

I have launched an ubuntu EC2 instance and tried to install Jenkins on it.
Below are the commands i used
sudo add-apt-repository ppa:webupd8team/java
sudo apt install oracle-java8-installer
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo apt-add-repository "deb https://pkg.jenkins.io/debian-stable binary/"
sudo apt install jenkins
My jenkins installation was successful but when i go to browser and tried
http://172.31.38.179:8080/.I am not able to get the jenkins page
Please suggest what i am missing here ?
Go to the security group attached to your ec2 instance.
Edit and add TCP on port 8080 from all and you are good to go . Please let me know if there’s any issues.

adding .net core to docker container with Jenkins

I'm trying to create a dockerfile that will build an image with .net core 2.0 and Jenkins. I'm kind of new to Docker but want to include .net core 2.0 in my container with Jenkins so I don't have to worry about .net core being installed on the target machine and can build .net core apps with Jenkins in my container. Am I missing something here?
it builds fine up until it runs the apt-get update command and I get the following error:
E: Malformed entry 1 in list file /etc/apt/sources.list.d/dotnetdev.list (component)
E: The list of sources could not be read.
I'm using the steps to install on ubuntu at this link:
https://learn.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x
My Dockerfile looks like this:
FROM jenkins
# Install .NET Core SDK
USER root
RUN mkdir -p /jenkins
WORKDIR /jenkins
ENV DOTNET_CORE_SDK_VERSION 2.0
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor >/jenkins/microsoft.gpg
RUN mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
RUN apt-get update
RUN apt-get install dotnet-sdk-2.0.0
As of this response you can use the following Dockerfile to get .NetCore 2 installed into the Jenkins container. You can obviously take this further and install the needed plugins and additional software as needed. I hope this helps you out!
FROM jenkins/jenkins:lts
# Switch to root to install .NET Core SDK
USER root
# Just for my sanity... Show me this distro information!
RUN uname -a && cat /etc/*release
# Based on instructiions at https://learn.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x
# Install depency for dotnet core 2.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl libunwind8 gettext apt-transport-https && \
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg && \
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg && \
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list' && \
apt-get update
# Install the .Net Core framework, set the path, and show the version of core installed.
RUN apt-get install -y dotnet-sdk-2.0.0 && \
export PATH=$PATH:$HOME/dotnet && \
dotnet --version
# Good idea to switch back to the jenkins user.
USER jenkins
You can run these commands inside the Docker container in order to install .NET Core. They can also be stored in a Dockerfile (as per #Zooly57)
Install the latest .NET Core 2.0:
sudo apt install libunwind8 gettext apt-transport-https
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 2.0
Or LTS version of .NET Core
sudo apt install libunwind8 gettext apt-transport-https
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel LTS
Contents of the script here:
https://github.com/dotnet/cli/blob/master/scripts/obtain/dotnet-install.sh
Fantastic answer by Dennis, it's exactly what I ended up doing. It was a nice introduction to Docker as well :-)
Here's my Dockerfile for Jenkins 2.249.2 (LTS at the time of writing) on Debian 9 (stretch):
# Extend Jenkins 2.249.2 on Debian 9 (stretch)
FROM jenkins/jenkins:2.249.2-lts
# Switch to root user to install .NET SDK
USER root
# Print kernel and distro info
RUN echo "Distro info:" && uname -a && cat /etc/*release
# Install needed tools and upgrade installed packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl apt-transport-https software-properties-common \
&& apt-get upgrade -y
# Add Microsoft repository for .NET SDK
RUN curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN apt-add-repository https://packages.microsoft.com/debian/9/prod/
# Install .NET SDK
RUN apt-get update \
&& apt-get install -y dotnet-sdk-3.1
# Switch back to jenkins user
USER jenkins
The dotnet command worked without setting any paths.
I guess when a newer version of Jenkins is released that uses Debian 10, I'll just update the FROM line then the Microsoft repository URL.
I believe you should follow below approach instead:
Develop your asp.net core app and check in to Git(Any source control)
Have a build server which has Jenkins, .Net Core, Docker installed
Configure Jenkins to communicate with Git (webhook/polling - to see if there is a check in)
And configure a Jenkins job which will do the following
Pull the latest from Git,
Restore,
Build,
Publish the asp.net core application,
Create a docker image which has a capability to run the asp.net core app in it
Upload the docker image just created to your Docker Hub
You may not want to do it exactly as mentioned above especially the source control part. But this approach works well.
I have followed this link while I made the above setup.
Hope it helps. Thanks!
For anyone who is struggling with this topic recently, this is what I added to the bottom of my Dockerfile to install the .NET SDK;
USER root
# Install dependencies
RUN apt-get install wget
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
# Install .NET SDK 6.0
RUN apt-get update;
RUN apt-get install -y apt-transport-https
RUN apt-get update
RUN apt-get install -y dotnet-sdk-6.0
RUN dotnet --version
This is based on installing the SDK on Ubuntu 18.04 as this is the version that AKS uses which was perfect for my scenario
https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#dependencies

Resources