I have Jenkins using kubernetes for creating ephemeral pods.
Recently I wanted to build .net solution so I built a custom image to inject .netSDK to my pod.
FROM jenkins/inbound-agent
USER root
RUN apt-get update;
RUN apt install wget
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y dotnet-sdk-5.0
USER jenkins
I just followed the steps from here.
After That I made sure that Jenkins will pull this new image when claiming a pod.
However when I run this pipeline:
pipeline {
parameters{
string(name: 'url', description: 'repository url')
string(name: 'branch', description: 'branch name')
string(name: 'agent', description: 'agent name')
}
agent { label "${params.agent}" }
stages {
stage('test') {
steps {
sh 'dotnet --info'
}
}
...
}
}
}
it throws an error message: dotnet: not found
/home/jenkins/agent/workspace/pipeline_DotnetBuild#tmp/durable-eb21aaa2/script.sh: 1:
/home/jenkins/agent/workspace/pipeline_DotnetBuild#tmp/durable-eb21aaa2/script.sh: dotnet: not found
So I did connect to the pod in bash mode to see what’s going on.
And I could execute:
jenkins#pod-f9xm0:~$ dotnet
Usage: dotnet [options]
Usage: dotnet [path-to-application]
…
The dotnet file is located in usr/bin/dotnet as well inside the pod.
So I am wondering what is going on here? I clearly misunderstand some concepts.
Thank you for your help and explanations!
After replicating your issue as closely as possible, I was getting similar results.
Starting dotnet from script with sh 'dotnet --info' is throwing an error
jenkins#157d7dfc5949:~$ cat test.sh
sh 'dotnet --info'
jenkins#157d7dfc5949:~$ ./test.sh
sh: 0: Can't open dotnet --info
Replacing sh 'dotnet --info' with /bin/bash -c dotnet --info fixed the issue.
jenkins#157d7dfc5949:~$ cat test.sh
/bin/bash -c dotnet --info
jenkins#157d7dfc5949:~$ ./test.sh
Usage: dotnet [options]
Usage: dotnet [path-to-application]
Options:
-h|--help Display help.
--info Display .NET information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
path-to-application:
The path to an application .dll file to execute.
Related
So I was trying to deploy a simple CD pipeline using docker by ssh’ing into my AWS Linux EC2 instance in the WSL2 terminal. The job is failing every time returning the following error:
Started by user Navdeep Singh Running as SYSTEM Building on the
built-in node in workspace /var/lib/jenkins/workspace/todo-dev
[todo-dev] $ /bin/sh -xe /tmp/jenkins6737039323529850559.sh + cd
/home/ubuntu/project/django-todo /tmp/jenkins6737039323529850559.sh:
2: cd: can’t cd to /home/ubuntu/project/django-todo Build step
‘Execute shell’ marked build as failure Finished: FAILURE
DockerFile contents:
FROM python:3 RUN pip install django==3.2
COPY . .
RUN python manage.py migrate
CMD [“python”,“manage.py”,“runserver”,“0.0.0.0:8000”]
Everything goes fine. This error cd: can’t cd to /home/ubuntu/project/django-todo Build step ‘Execute shell’ marked build as failure Finished: FAILURE is not an actual.
Your agent Node is not online.
To fix the problem, find commands on your jenkins web page after an agent setup. You need to run those commands from your terminal. See the screenshot for more details.
Make sure that your jenkins public IP and node agent public IP are the same. If an error occurs, you need to run some commands on the terminal. This is not a real error.
this issue follow this step which i give you
For Agent--->
change your ip here(44.203.138.174:8080) to your EC2 ip
1.curl -sO http://44.203.138.174:8080/jnlpJars/agent.jar
2.java -jar agent.jar -jnlpUrl http://44.203.138.174:8080/manage/computer/todo%2Dagent/jenkins-agent.jnlp -secret beb62de0f81bfd06e4cd81d1b896d85d38f82b87b21ef8baef3389e651c9f72c -workDir "/home/ubuntu"
For JOb --->
sudo vi /etc/sudoers
then add this command below root access in sudoers file
jenkins ALL=(ALL) NOPASSWD: ALL
3.then goto the ubuntu directory using cd .. then run this codes
grep ^ubuntu /etc/group
id jenkins
sudo adduser jenkins ubuntu
grep ^ubuntu /etc/group
4.restart the jenkins relogin
sudo systemctl stop jenkins
then you good to go
When I run Docker build with my project Docker+Selenium+Pytest in Jenkins CI with tests that end with the SUСCESS status - the build is pushed and the results are published to reports, and if at least one test fails - the build fails and the results are not published
Build Error: The command 'pytest test_page.py -s -v --alluredir=reports/allure-results' returned a non-zero code: 1
Maybe my instructions for Docker are incorrectly configured.
My DockerFile
FROM python:latest as python3
FROM selenium/standalone-chrome
USER root
WORKDIR /my-projest
ADD . /my-projest
RUN pip3 install --no-cache-dir --user -r requirements.txt
RUN sudo pip3 install pytest
RUN ["pytest", "test_page.py", "-s", "-v", "--alluredir=reports/allure-results"]
and SHELL Command
echo "Build docker image and run container"
docker build -t $IMAGE_NAME .
docker run -d --name $CONTAINER_NAME $IMAGE_NAME
echo "Copy allure-results into Jenkins container"
rm -rf reports; mkdir reports;
docker cp $CONTAINER_NAME:my-project/reports/allure-results reports
It may be that your tests are failing on an assertion and that failed assertion may be throwing the non 0 error code.
this link outlines the expected exit codes for each scenario
Exit code 0
All tests were collected and passed successfully
Exit code 1
Tests were collected and run but some of the tests failed
Exit code 2
Test execution was interrupted by the user
Exit code 3
Internal error happened while executing tests
Exit code 4
pytest command line usage error
Exit code 5
No tests were collected
Problem is when testcases are failing docker build is exiting with non-zero code.
One way around to generate report even when testcases are failed
echo "Build docker image and run container"
docker build -t $IMAGE_NAME .
echo "Copy allure-results into Jenkins container"
rm -rf reports
docker create -it --name $CONTAINER_NAME $IMAGE_NAME /bin/bash
docker cp $CONTAINER_NAME:my-project/reports/allure-results ./reports
docker rm -f $CONTAINER_NAME
You can user report copy part in Jenkins pipeline in post stage under always block, so that whether build pass or fail you can always get reports.
I found a solution to this issue:
added at the end of the RUN command - exit 0
I am trying to do some SonarCloud code analyses on Jenkins with a donet docker container that is already built by my organization. However, I have to install the sonnarscanner tool on top of it, but I am getting permission denials when running the tool.
This is what I've tried so far:
stage("Pull dotnet image") {
dotnetCoreImage = dockerImage("dotnet2.0")
}
dotnetCoreImage.inside() {
stage("Start sonar scanner") {
sh "dotnet tool install --tool-path /tmp/.donet/tools dotnet-sonarscanner; \
chmod 777 /tmp/.donet/tools/ -R;
export PATH=/tmp/.donet/tools; \
dotnet sonarscanner begin \
/d:sonar.host.url=https://sonarcloud.io \
/v:'1.0' \
/d:sonar.cs.opencover.reportsPaths='src/test/coverage/*.opencover.xml'\
/d:sonar.branch.name=${env.BRANCH_NAME}"
}
But I get the following errors:
16:00:46.527 16:00:46.527 WARNING: Error occurred when installing the loader targets to '/.local/share/Microsoft/MSBuild/4.0/Microsoft.Common.targets/ImportBefore/SonarQube.Integration.ImportBefore.targets'. 'Access to the path '/.local/share/Microsoft/MSBuild/4.0/Microsoft.Common.targets/ImportBefore' is denied.'
So my question is if there is a way to run inside the docker image with more permissions such as root.
(Cannot do sudo since it is not installed in the docker image)
We have a ASP.Net MVC app and which works fine when we run even locally in debug mode from Visual Studio.
We have 4 Class library projects and one web api project. Following is my docker file:
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY xxxxx/*.csproj ./xxxxx/
COPY yyyyyy/*.csproj ./yyyyy/
# copy everything else and build app
COPY xxxxx/ ./xxxxx/
COPY yyyyy/ ./yyyyy/
RUN nuget restore
WORKDIR /app/GetThree
RUN msbuild /p:Configuration=Release
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/xxxxx/. ./
Once I build the docker file, everything compiles properly and build is successful also (all Nuget packages are restored) and I am able to create the container as well. But unfortunately whenever I try to browse to my web-app (I got the IP address of the container as this is windows base) but unfortunately I get HTTP 500 internal server error immediately. I have made sure that the HTTPERROR section is set for detailed error message.
As soon as I navigate to the ip address I get this 500 error and unfortunately not much is availble in the logs (Application or System) which will help me as to what the issue could be. Any help?
Following is the command I use to build and run the container:
docker build -f .\GetThree\Dockerfile -t threecms/cmsdocker:1.0
docker run --name threecms --rm -it -p 8100:80 threecms/cmsdocker:1.0
To browse the site I get the IP Address (using docker exec threecms ipconfig) and I browse it using: http://ipadress:8100
UPDATE 1:-
I created one more image from above image using following dockerfile ( urlrewrite is the URLREWRITE module install script)
FROM threecms/cmsdocker:1.0
WORKDIR C:/
Copy urlrewrite.ps1/ .
RUN "Powershell ./urlrewrite.ps1"
RUN Install-WindowsFeature Web-Mgmt-Service; \
New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force; \
Set-Service -Name wmsvc -StartupType automatic;
URL REWRITE PS1 script:
New-Item c:/msi -ItemType Directory
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile c:/msi/WebPlatformInstaller_amd64_en-US.msi
Start-Process 'c:/msi/WebPlatformInstaller_amd64_en-US.msi' '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA /Log:c:/msi/WebpiCmd.log
Then I ran the container using following command:-
docker run --name threecms2 -d cmswindfeature/cmswinfeature:3.0
And now whenever I got to my application from browser it gives me the actual error msg which is:
Access to the path 'C:\inetpub\wwwroot\App_Data\TEMP\PluginCache\umbraco-plugins.373F7AAE388A.hash' is denied.
UPDATE:-2 RESOLVED
So to Resolve above error I ran the following Powershell script (To add required Permissions) and Boom I was able to access my site and its working now:-
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl = Get-ACL "C:\inetpub\wwwroot"
$acl.AddAccessRule($accessRule)
Set-ACL -Path "C:\inetpub\wwwroot" -ACLObject $acl
You need to find out from the application pool for the website what is the identity it is running under (by default this is Application Pool Identity) and grant that the correct permissions. normally, it is IIS_IUSRS, you can try the following steps to solve the problem:
Right Click Folder-> go to Security Tab-> Click on Edit-> Click on Add-> Click on Advanced
-> Find Now-> Give Permission to IIS_IUSRS (Full Control)-> Click On OK-> Click On OK->
Click On Full Control in allow-> Click On OK.
Note: If above things are not working then try to give same permission to NETWORK,NETWORK SERVICE Users
I am new to docker and using this as an example on how to learn. I am trying to create a dockerfile which would allow me to run plex on my windows sever. An awesome post created on the Plex forums describes how to perform the tasks using powershell, and so I wanted to see if it would be possible to create an image using these commands.
Here is what I have so far:
FROM microsoft/windowsservercore
RUN Get-ChildItem "$Env:SystemRoot\Servicing\Packages\*Media*.mum" | ForEach-Object { (Get-Content $_) -replace 'required','no' | Set-Content $_}
RUN Add-WindowsFeature Server-Media-Foundation;
RUN Invoke-WebRequest -OutFile Plex-Media-Server-1.12.3.4973-215c28d86.exe "https://downloads.plex.tv/plex-media-server/1.12.3.4973-215c28d86/Plex-Media-Server-1.12.3.4973-215c28d86.exe" -UseBasicParsing;
RUN .\plex.exe /quiet
RUN start 'C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe'
EXPOSE 32400/tcp
I have removed comments for formatting.
So I have two questions,
first : this does not seem to run when using docker build -t test_plex .
I get the following error:
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Windows\System32\Dockerfile: The system cannot find the file specified.
second: using PowerShell would this all run in parallel? or is there some kind of wait command.
Any help/tips would be great, thanks for your time (sorry about long post)
It looks like you're running docker build -t test_plex . in C:\Windows\System32\. Move to an empty folder with just your Dockerfile and run the command again.
The . is the location of your build context, you can also change that location to a different path.
Keep in mind that when you run docker build -t test_plex . the "build context" or the directory that you're in when you run it is relevant to the build. Depending on your system all the files at the location you're running that command will be copied into the build vm.