Jenkins windows slave via openssh fails to start - jenkins

I'm trying to connect a windows agent to jenkins with no luck. I'm using open ssh and no verification for now during setup. When I launch the agent, Jenkins can reach it and it puts the remote.jar in the requested folder, but it still has an issue starting the agent. I get no error description whatsoever
SSHLauncher{host='NLQA1', port=22, credentialsId='10314a78-c648-4891-aa78-c5510875e8e7', jvmOptions='', javaPath='c:/jenkins2/jdk/bin/java.exe', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=210, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[06/20/19 13:36:26] [SSH] Opening SSH connection to NLQA1:22.
[06/20/19 13:36:27] [SSH] WARNING: SSH Host Keys are not being verified. Man-in-the-middle attacks may be possible against this connection.
[06/20/19 13:36:28] [SSH] Authentication successful.
[06/20/19 13:36:28] [SSH] The remote user's environment is:
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Admin\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=NLQA1
ComSpec=C:\WINDOWS\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
GIT_SSH=C:\Program Files\TortoiseGit\bin\TortoisePLink.exe
HOMEDRIVE=C:
HOMEPATH=\Users\Admin
ICU_DATA=c:\Usd91\BIN
LOCALAPPDATA=C:\Users\Admin\AppData\Local
NUMBER_OF_PROCESSORS=2
OneDrive=C:\Users\Admin\OneDrive
OS=Windows_NT
Path=C:\app\client\Admin\product\12.1.0\client_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;c:\Gnuwin32;C:\Users\Admin\AppData\Local\Microsoft\WindowsApps;C:\App;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3f02
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=Admin#Domain#NLQA1 $P$G
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SSH_CLIENT=172.x.x.x 63458 22
SSH_CONNECTION=172.x.x.x 63458 172.x.x.x 22
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\TEMP
TMP=C:\TEMP
USERDOMAIN=Domain
USERNAME=Admin#Domain
USERPROFILE=C:\Users\Admin
windir=C:\WINDOWS
[06/20/19 13:36:28] [SSH] Starting sftp client.
[06/20/19 13:36:28] [SSH] Copying latest remoting.jar...
Source agent hash is D2D1A740134BD20D6F0855B356344342. Installed agent hash is D2D1A740134BD20D6F0855B356344342
Verified agent jar. No update is necessary.
Expanded the channel window size to 4MB
[06/20/19 13:36:29] [SSH] Starting agent process: cd "c:/jenkins2" && c:/jenkins2/jdk/bin/java.exe -jar remoting.jar -workDir c:/jenkins2
Slave JVM has terminated. Exit code=0
[06/20/19 13:36:29] Launch failed - cleaning up connection
[06/20/19 13:36:29] [SSH] Connection closed.
Agent is running adoptopenjdk 11 with eclipsej9, Slave JVM has terminated. Exit code=0 is all information I get back from Jenkins. I can run the agent if I rdp to the machine and do c:/jenkins2/jdk/bin/java.exe -jar remoting.jar -workDir c:/jenkins2 manually, so it is not that the jar can't be started at all. jnlp is working as well, but I'd like to use the ssh route. Do you have a clue what is wrong or what I have to do to get more information regarding the failed launch?

I found the answer at the ssh-slaves-plugin git repository. I'll quote it here so it will be here in the future.
Launch Windows slaves using Microsoft OpenSSH
The current version of the plugin does not run directly on PowerShell, you have to use prefix and suffix settings to trick the command and make it works, Windows 10 machines can run as SSH agents with the Microsoft OpenSSH server by using:
Prefix Start Agent Command
powershell -Command "cd C:\J\S ; C:\J\S\jdk\bin\java.exe -jar remoting.jar" ; exit 0 ; rem '
Suffix Start Agent Command
'
EDIT 16-08-2019
After installing windows updates on the machine I had to change the prefix to
powershell -Command "cd C:\J\S ; C:\J\S\jdk\bin\java.exe -jar remoting.jar" ; exit 0 ; # '
The change from rem to # make it working again. The error I was getting was :
The string is missing the terminator: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Looks like its the && operator. simple example
powershell -Command "cd c:/" ; exit 0 ; rem 'cd && echo "abc"'
Adding the prefix and the suffix fixed it for my. If someone knows why wrapping it in another powershell command makes it work feel free to elaborate.

Related

Jenkins BUILD_LOG evaluates to [...truncated ]

I am trying to set the Build name/Build description based on the outcome of a shell script.
For example, I am executing the following lines in shell:
echo `date`
if [ $test == true ]then
echo "BuildSuccess"
else
echo "NoBuild"
fi
I am then running the build step "Changes build description". In this, I have added the macro:
${BUILD_LOG,maxLines=1}
After running the job I get the output as:
[SSH] executing...
Thu May 20 00:47:42 PDT 2021
BuildSuccess
[SSH] completed
[SSH] exit-status: 0
New run description is '[...truncated 478 B...]
'
Evaluated macro: '#37'
New run name is '#37'
Finished: SUCCESS
Can anyone help me understand why the macro is getting evaluated to [...truncated 478 B...]?
Is there a way I can capture the text "BuildSuccess" from the log?
I am in effect trying to capture the last line of the build log.
Please note that this is a freestyle project and not a pipeline.
I solved a similar issue by:
BUILD_LOG_REGEX
email-ext plugin
Here is a tutorial http://siddesh-bg.blogspot.com/2012/04/using-buildlogregex-in-jenkins-email.html .
By BUILD_LOG_REGEX the above mentioned plugin is able to query and extract parts of the build log.

How to install a TFS 2017 agent on Windows Server using Powershell Script?

I am trying to install the VSTS build agent on a Windows Server 2016 using the below Powershell script but the script fails with the below error.
$tfsUrl=”http://vwmaztfsapp:8080/tfs/Collection”
$pool = ”Cli Execution”
$username = ”dev.local\svc_tfsAcc”
$password = ”MyPassword”
$AgentName = "Aut1"
CD "$AgentFolder\vsts-agent-win7-x64-2.122.1-Aut6\"
# configure agent to run as a Windows service that logs on as a domain account
& .\config.cmd --unattended -–url "$tfsUrl" --auth "integrated" -–pool "$pool" -–agent "$AgentName" --work "$AgentFolder\$AgentName" –-runAsService -–windowsLogonAccount "$username" –-windowsLogonPassword "$password"
Error below -
PS C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6> C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6\InstallAgent.ps1
config.cmd : Unrecognized command-line input arguments: 'unattended'. For usage refer to: .\config.cmd --help or ./config.sh --help
At C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6\InstallAgent.ps1:49 char:1
+ & .\config.cmd --unattended -–url "$tfsUrl" --auth "integrated" -–poo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Unrecognized co...onfig.sh --help:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Is there something that I am missing?
I need to install the agent on multiple servers and that's the reason I want to automate this process.
Update
I was using command without "" such as:
.\config.cmd --unattended --url https://dev.azure.com/patricklu2020 --auth pat --token n2upx6epgl4srovzgp6is5wytjfkspvv6uvxxxx --pool default --agent myAgent --work D:\agent_work
If you want to configure as a service, you need to configure the agent from an elevated PowerShell window, this is required.
I would suggest you directly run the command from an elevated powershell window first, and then check if you are able to configure the agent correctly.
This kind of error maybe caused by passing arguments incorrectly. Kindly verify it.

Jenkins does not abort on SVN error E175002

I am calling svn ls from Jenkins on a SVN directory to get a list of paths that match a certain pattern (that I later process further).
Maybe not very nice, but this is currently how it works:
def proc = bat (returnStdout: true, script: '#svn ls https://path/to/my/repo/trunk -R --trust-server-cert-failures=unknown-ca --non-interactive | findstr /R "^[^_].*_src/$" | findstr /R "^FolderA ^FolderB" | findstr /V "_test"').trim()
Problem
Sometimes due to connection issues the svn ls command fails and the Jenkins job aborts (which is perfectly ok because it is the expected behavior.
Sometimes however, it seems that only some folders / sub-folders are not accessible temporarily and I get an error message, but it seems not an error signal from the svn ls:
svn: E175002: Unexpected server error 500 'Internal Server Error' on 'path/to/a/folder
This is a problem, because the pipeline does not abort, but continues and the content of proc only contains parts of the result, but not the full result.
Is there any way to detect this case where the error occurs? Please note, that not the occurrance of the E175002 error is my problem, but its detection.

PhantomJS failed to load URL on Jetty running on Jenkins

I want to use the Siesta testing Framework with PhantomJS on a local server and there is no problem. I worked like in http://www.bryntum.com/forum/viewtopic.php?f=20&t=3068 and on my machine, there were nothing to complain about, so i want to combine it with Jenkins.
But using Jenkins an Error 403 appears.
What I do:
Copy the files of my project in the webapps folder of Jetty (incl.
Framework )
Start the jetty server (so far no problems)
Use the PhantomJs of the framwork on my
localhost:port/project/index.html
And there my Problem starts:
Failed to load URL: localhost:port/project/index.html(Status 403)
I searched for some results but didn't find anything that solves this problem.
Every hint is welcome
Thanks
To see what i've done:
My Jenkins Shell Script
JETTY="jetty-distribution-9.2.0.v20140526"
JETTYWEB="$JETTY/webapps"
DIR="$WORKSPACE/$JETTYWEB/myProject/src/test"
PHANTOM="$DIR/Siesta_Framework/bin"
rm -r "$JETTYWEB/myProject/"
mkdir "$JETTYWEB/myProject/"
cp -pr "src/" "$JETTYWEB/myProject/"
chmod u+x -R $JETTYWEB/
cd $WORKSPACE/$JETTY
# Start des Servers
java -DSTOP.PORT=11183 -jar start.jar -DSTOP.KEY=tadam &
sleep 5
#jenkins "$DIR/browse-autmation.html?phantom=true&enableCodeCoverage=false&hasPreviousReport=false&page=0
cd $PHANTOM
#curl http://localhost:11182/myProject/src/test/browse-automation.html
./phantomjs "http://127.0.0.1:11182/myProject/src/test/browse-automation.html"
#"http://.../ci/job/test-phatomJS/ws/src/test/browse-automation.html?phantom=true&enableCodeCoverage=false&hasPreviousReport=false&page=0"
#curl http://127.0.0.1:11182/myProject/src/test/Siesta_Framework/bin/phantomjs
sleep 15
# Stop des Servers -DSTOP.KEY=tadam
cd $WORKSPACE/$JETTY
java -DSTOP.PORT=11183 -DSTOP.KEY=tadam -jar start.jar --stop
And the Result was:
[EnvInject] - Loading node environment variables.
Building remotely on ja_lin01 in workspace /var/opt/coinop/data/workspace/test-phatomJS
Fetching changes from the remote Git repository
Fetching upstream changes from gitlab#moso-ci-srv.novalocal:b.rohn/myProject.git
Checking out Revision a056b4ac6a7b47a4e77f3f80c5b7cbc51167cefc (origin/master)
[test-phatomJS] $ /bin/bash -xe /tmp/hudson8419984949815797813.sh
+ JETTY=jetty-distribution-9.2.0.v20140526
+ JETTYWEB=jetty-distribution-9.2.0.v20140526/webapps
+ DIR=/var/opt/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/myProject/src/test
+ PHANTOM=/var/opt/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/myProject/src/test/Siesta_Framework/bin
+ rm -r jetty-distribution-9.2.0.v20140526/webapps/myProject/
+ mkdir jetty-distribution-9.2.0.v20140526/webapps/myProject/
+ cp -pr src/ jetty-distribution-9.2.0.v20140526/webapps/myProject/
+ chmod u+x -R jetty-distribution-9.2.0.v20140526/webapps/
+ cd /var/opt/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526
+ sleep 5
+ java -DSTOP.PORT=11183 -jar start.jar -DSTOP.KEY=tadam
WARNING: System properties and/or JVM args set. Consider using --dry-run or --exec
2014-07-01 15:37:10.895:INFO::main: Logging initialized #1014ms
2014-07-01 15:37:12.451:INFO:oejs.Server:main: jetty-9.2.0.v20140526
2014-07-01 15:37:12.480:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/data/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/] at interval 1
2014-07-01 15:37:13.232:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#57cd102a{/myProject,file:/data/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/myProject/,AVAILABLE}{/myProject}
2014-07-01 15:37:13.255:INFO:oejs.ServerConnector:main: Started ServerConnector#6d622548{HTTP/1.1}{0.0.0.0:11182}
2014-07-01 15:37:13.255:INFO:oejs.Server:main: Started #3388ms
+ cd /var/opt/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/myProject/src/test/Siesta_Framework/bin
+ ./phantomjs http://127.0.0.1:11182/myProject/src/test/browse-automation.html
/var/opt/coinop/data/workspace/test-phatomJS/jetty-distribution-9.2.0.v20140526/webapps/myProject/src/test/Siesta_Framework/bin
Launching PhantomJS 1.6.0 at http://127.0.0.1:11182/myProject/src/test/browse-automation.html
Failed to load URL: http://127.0.0.1:11182/myProject/src/test/browse-automation.html?phantom=true&enableCodeCoverage=false&hasPreviousReport=false&page=0(status: 403)
Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
Build step 'Execute shell' marked build as failure
2014-07-01 15:37:24.931:INFO:oejs.ServerConnector:Thread-0: Stopped ServerConnector#6d622548{HTTP/1.1}{0.0.0.0:11182}
Finished: FAILURE
after long searching i noticed, that the phantomjs call doesn't have all the informations it need. It needs the directory itself. So my resolution was: install phantomjs on the linux server and use this phantomjs, including the directory and the phantom script of the framework: now it works.
my actually call is:
./phantomjs "$DIR/phantomjs-launcher.js" $DIR http://127.0.0.1:11182/myProject/browse-automation.html
Situation: i cd in my phtomjs directory on the linux machine and give it the "DIR" of my framework/bin

Invoke build using sshexec in remote machine does not work

I have setup a SSH server in my remote machine (Windows) executing the following commands in my windows machine.
<sshexec host="host"
port="port"
username="uname"
password="pass"
trust="true"
Command="(E:; cd \buildProjectDemo\build\; ant -propertyfile configurable.properties build-installer)"
/>
But, the command does not execute in the remote machine. It just gives the output as,
hostExec:
[sshexec] Connecting to host
[sshexec] cmd : (E:; cd \buildProjectDemo\build\; ant -propertyfile configurable.properties build-installer)
BUILD SUCCESSFUL
What could be the problem?
The command needs to be changed as
Command="e: && cd E:\buildProjectDemo\build &ant -propertyfile configurable.properties build-installer"

Resources