getting well formed output from ant - sshexec in groovy script - ant

my problem is, that the output from the ant task alwas has some [ssh-exec] infotext at the beginning. can i suppress / disable that?
my code so far:
def ant = new AntBuilder()
// .... variable definition ...
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls')
>>> output:
[sshexec] Connecting to foomachine.local:22
[sshexec] cmd : ls
[sshexec] oldarchive.gz
[sshexec] newarchive.gz
[sshexec] empty-db.sh
[sshexec] testfile.py
i just want to have the raw output from the cmd i execute...
some ideas?!

You can save the raw output inside an Ant property:
def ant = new AntBuilder()
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls',
outputproperty: 'result')
def result = ant.project.properties.'result'

the problem is that outputproperty is not working properly (it does not set the ant variable).
I often use trycatch from antcontrib to test if error occurs instead of reading return value.
Example :
<trycatch>
<try>
<sshexec host="#{host}" failonerror="true" username="${username}" password="${password}" timeout="${ssh.timeout}" command="#{command}" usepty="#{usepty}" trust="true" />
</try>
<catch>
<echo>Service already stopped!</echo>
</catch>
</trycatch>

I tripped over the same issue in gradle and from there I had to change the way to access the property:
According to the official gradle doc 3.3
println ant.antProp
println ant.properties.antProp
println ant.properties['antProp']
is the correct way to go.
def ant = new AntBuilder()
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls',
outputproperty: 'result')
def result = ant.properties.'result'
Hope this helps people in the same situation. Cheers

Related

Avoid printing passwords in Jenkins console

We have Jenkins stage which is calling a "GetVMPassword" function from library. The function returns credential and it will be used to login remote server. We dont want to print the "ssh command" and "calling a funtion command" and its reponse on stage logs. So we used ā€˜#!/bin/sh -e \nā€™ before every command. Because if we print, this could reveal the remote server credentials in the stage log. This was working when we don't use "parallel execution" block.
When we include "ssh command" and "calling a function command" inside "parallel execution" block, passwords are printed in stage logs.
How can we avoid printing in stage logs the library command and its response when we use "parallel execution" block ?
This is snippet of my stage and parallel execution block.
Jenkins Version: 2.235.3
#Library ('MyLib_API') _
pipeline{
agent {
label 'master'
}
stages{
stage('BuildAll'){
steps{
script{
def executions = APPSERVERS.split(',').collectEntries {APPS ->
["Execution ${APPS}": {
stage(APPS) {
APP_USERNAME = "ubuntu"
response = getPassword("${APPS}","${APP_USERNAME}")
sh '#!/bin/sh -e \n' + "sshpass -p '${response}' ssh -o StrictHostKeyChecking=no ${APP_USERNAME}#${APPS} 'ls'"
sleep 2
}
}]
}
parallel executions
}
}
}
}
}
"getPassword" is the function in library used to get the vm password dynamically.
"APPSERVERS" values we are getting from Active choice parameters option.This has list of IP's of servers.
Please help me to hide those library commands and responses from stage logs.
We have tried below options.
Used set +x and it is not worked for us.
Password masking plugin will not work. Since response from the command will get print for our case.
We tried routing all the execution of commands to file and tried fetching it from there. In this option, also while parsing the file logs are printed in stage logs.
Try starting your script with set +x, if not use password masking plugins
as mentioned here - https://issues.jenkins.io/browse/JENKINS-36007
You can use input to pass the credential and mask it in log.
Here is a detailed answer stackoverflow credentials masking
you can use this as well it works for me.
node('Node Name'){
println('Please enter the username')
def userName = input(
id: 'userName', message: 'VPN Username', parameters: [
[$class: 'hudson.model.TextParameterDefinition', defaultValue :'', name: 'Username', description: 'Please enter your username']
])
println('Please enter the password')
def userPassword = input(
id: 'userPassword', message: 'VPN Password', parameters: [
[$class: 'hudson.model.PasswordParameterDefinition', defaultValue :'', name: 'Password', description: 'Please enter your password']
])
connectToClient = bat(returnStdout: true, script: 'start Forticlient connect -h v3 -u ' + userName+ ':' + userPassword)
stage('Deploy (Test)'){
withCredentials([usernamePassword(credentialsId: 'IH_IIS_JENKINS', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
bat"msdeploy command"
}
}
}

Execute PHPUnit Testcases from PHPStorm using Lando

I've successfully configured the PHPStorm with the Docker containers served by Lando. Still, when I'm trying to execute the test, for instance, the core/modules/system/tests/src/Functional/System/HtaccessTest.php it's throwing me the following error:
Testing started at 1:00 AM ...
[docker://devwithlando/php:7.2-apache-2/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter "/(Drupal\\Tests\\system\\Functional\\System\\HtaccessTest::testIndexphpRewrite)( .*)?$/" --test-suffix HtaccessTest.php /opt/project/core/modules/system/tests/src/Functional/System --teamcity
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Testing /opt/project/core/modules/system/tests/src/Functional/System
Drupal\Core\Installer\Exception\AlreadyInstalledException : <ul>
<li>To start over, you must empty your existing database and copy <em>default.settings.php</em> over <em>settings.php</em>.</li>
<li>To upgrade an existing installation, proceed to the update script.</li>
<li>View your existing site.</li>
</ul>
/opt/project/core/includes/install.core.inc:534
/opt/project/core/includes/install.core.inc:114
/opt/project/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php:296
/opt/project/core/tests/Drupal/Tests/BrowserTestBase.php:573
/opt/project/core/tests/Drupal/Tests/BrowserTestBase.php:406
Time: 22.67 seconds, Memory: 6.00MB
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Process finished with exit code 2
I made a wild guess the issue could have been with the database connection, hence I've tried with all the following options i.e.:
mysql://drupal8:drupal8#database:3306/drupal8
mysql://drupal8:drupal8#database/drupal8
mysql://drupal8:drupal8#localhost:32860/drupal8
<!-- 32860 is nothing but the port for external_connection. -->
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_BASE_URL" value="http://my-lando-app.lndo.site/"/>
<!-- Example SIMPLETEST_DB value: mysql://username:password#localhost/databasename#table_prefix -->
<env name="SIMPLETEST_DB" value="mysql://drupal8:drupal8#database:3306/drupal8"/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/app/sites/simpletest/browser_output"/>
<!-- To have browsertest output use an alternative base URL. For example if
SIMPLETEST_BASE_URL is an internal DDEV URL, you can set this to the
external DDev URL so you can follow the links directly.
-->
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>
<!-- To disable deprecation testing completely uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=''/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS_PHANTOMJS" value=''/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
</php>
I'm also attaching the output of my lando info command, just in case if it's helpful:
[ { service: 'appserver',
urls:
[ 'https://localhost:32861',
'http://localhost:32862',
'http://my-lando-app.lndo.site/',
'https://my-lando-app.lndo.site/' ],
type: 'php',
healthy: true,
via: 'apache',
webroot: '.',
config: { php: '/Users/rishi/.lando/config/drupal8/php.ini' },
version: '7.2',
meUser: 'www-data',
hostnames: [ 'appserver.mylandoapp.internal' ] },
{ service: 'database',
urls: [],
type: 'mysql',
healthy: true,
internal_connection: { host: 'database', port: '3306' },
external_connection: { host: '127.0.0.1', port: '32860' },
healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
creds: { database: 'drupal8', password: 'drupal8', user: 'drupal8' },
config: { database: '/Users/rishi/.lando/config/drupal8/mysql.cnf' },
version: '5.7',
meUser: 'www-data',
hostnames: [ 'database.mylandoapp.internal' ] } ]
You need to run
$ docker network ls
Then copy the "network id" for the "appserver".
Now, lets update your PHPStorm settings. Go to "Languages > PHP > Test Frameworks"
Then click the folder icon next to the "Docker Container" definition.
Now, change the Network Mode to your network id that you copied at the beginning.

scp all files within a DIR to remote using ant

I was trying to copy all the files within a directory from windows to unix within groovy method using following. But it does give an error saying No such file or directory
def antMove = new AntBuilder()
antMove.scp(trust: 'true',
file: "D:\\MyFolder\\input\\*",
todir: "username#[IP]:/tmp/rw_input/",
port: "22",
keyfile: Key,
passphrase: Passphrase,
verbose: "true")
I tried different option as well like *.* and * . But no luck
If I give just one file name here like test.txt its working fine
Thanks
Fileset can be added in the following way:
def ant = new AntBuilder()
ant.scp(
todir: "username#[IP]:/tmp/rw_input/",
verbose: true,
keyfile: "key",
trust: true
) {
fileset(dir: "D:\\MyFolder\\input\\") {
include(name: '*')
}
}

grunt deploy not deploy to target

i'v try to deploy the grunt output folder ( dist ) to server space using grunt-deploy in Jenkins. it return success message after grunt deploy.but it actually not deploy to given target.and there is option for username and password of server.so i think its not secure method .if yes give me a correct method for that.also there is no option for source path . this is my deploy code.
deploy: {
liveservers: {
options:{
servers: [{
host: 'host',
port: 'port',
username: 'user',
password: 'pass'
}],
cmds_before_deploy: [],
cmds_after_deploy: [],
deploy_path: '/home/testdeploy'
}
} }
please help me :(
Use the mkdir command to create a releases subfolder:
cd /home/testdeploy
mkdir releases
then retry. The existence of releases is a hardcoded assumption in the source
References
grunt-deploy: deploy.js source

Grails deploy: no such warName for class: Tomcat

When I try to deploy to a remote Tomcat server using grails prod deploy tomcat I get the error:
Has anybody encountered that?
P.S. On the contrary, the command mvn tomcat7:deploy works.
Problem was resolved by adding def warName = configureWarName() to Tomcat.groovy
...
switch (cmd) {
case 'deploy':
war()
def warName = configureWarName()
println "Deploying application $serverContextPath to Tomcat"
deploy(war: warName, url: url, path: serverContextPath, username: user, password: pass)
break
....

Resources