Use XMLStarlet in Azure DevOps Bash task - bash

I want to use xmlstartlet within a Bash task in Azure DevOps to edit the below XML.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
I want to make this code to the below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<PostFlow name="PostFlow">
<Request>
<Step>
<Name>EV-ExtractParameters</Name>
</Step>
</Request>
<Response/>
</PostFlow>
But stuck at getting to install XMLstarlet in the build server. Has anyone been able to use this in Azure DevOps Bash task?
I have tried to use an agent demand, but that didn't work.

In the Microsoft Hosted agents the xmlstarlet tool not installed in the machine, so you can't just use it.
You need to add a Bash task to install the tool, then you can use it.
Example in the .yaml pipeline to the Bash task:
-bash: |
sudo apt-get install xmlstarlet
Then use it with the command xmlstarlet [<options>] <command>.

Related

curl Doesn't get file but firefox and any browsers could get

I want to create a Jenkins slave as a docker. so I use this Github link to create a Ubuntu Jenkins slave.
In this Dockerfile there is a section that use curl to get a jar file.
curl --create-dirs -sSLo /usr/share/jenkins/slave.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/4.0/remoting-4.0.jar
When I want to curl a jar file with curl, didn't work but by any browsers, I could download the jar file.
Why curl bash command doesn't work?
Are you using a proxy in your web browser ?, if so, just:
export http_proxy=http://ip:port
export https_proxy=http://ip:port

Unable to configure the PATH environment variable in Kudu shell via XDT

I am trying to set the PATH environment variable for a web app I am building in Azure in python. I tried to use something like os.environ.setdefault('PATH', 'pandoc-2.14.1-1-amd64.deb') locally, however this does not seem to work once uploaded. I have also tried setting the path in the configuration section on the azure portal, but get the following error:
I have seen posts like
setting the webapp %PATH% environment variable in azure.
The post recommends adding a file called applicationHost.xdt to the home/site directory, which should set the PATH variable automatically. However, I am unable to upload applicationHost.xdt to the files in the directory. This is either because the file UI interface no longer exists, or I am unable to access it. Has the ability to upload via the UI been discontinued?
The only other workaround I can think of is to use echo/cat in the Kudu bash shell to create the applicationHost.xdt manually. This is very tricky. Are there any online tools that, given an input of the contents of a file, create the bash script to generate that file from scratch?
You could add a App settings to you web app, like below:
Then, restart your web app, in Kudu console, you could check it.
Note: App setting names must be unique, so when you use PATH as key it is already configured while deploy so while using in App setting from portal use a different Key name.
As a workaround, you can achieve that through an XDT Transform (XML Document Transform).
Yes, you can use echo to create the same. Simple copy paste the content of the file to be inside single quote ' and stream it into the file already created using echo command.
/home>echo '<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>' > applicationHost.xdt
Verify the contents using cat command

Mounting home directory in Visual Studio docker environment

I have the following configuration in my .csproj file to mount my AWS credentials when running .NET core in a Docker container:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileRunArguments>-v /C/Users/myname/.aws:/root/.aws</DockerfileRunArguments>
</PropertyGroup>
However, I need this to work across different development environments. I've tried replacing myname with ${env.UserName} or %USERNAME% but in both cases I get Error response from daemon: mkdir C:\Users\[variable is here]: Access is denied.
The docker run command is fine if I hard-code my user name as shown.

Spring boot application wont start in openshift

I created openshift project with DIY cartridge, added postresql for DB.. now I pushed sources to cloud, but I'm getting error like the guy here (but he was not using springboot): I can't start tomcat 7 server on linux openshift - Failed to start end point associated with ProtocolHandler ["http-nio-12345"]
Failed to start end point associated with ProtocolHandler
It's obvious that if I run the app twice the error message 'Failed to start end point associated with ProtocolHandler' appears. I tried rhc app-tidy, restarted APP via openshift interface, i made change, pushed to cloud, build success, but the message appeared again. How to stop the app so that I can run it properly? Didn't the app being stopped after the restart I performed?
UPDATE: Have I chosen the right steps? (with DIY cartridge), do You have a simple (& working) guide how to deploy such an app to openshift? I tried few I found over the net, but none of them worked :(
Here is steps I follow using DIY cartridge, hope this would help
Go to home directory of project perform following tasks
Create Settings.xml and refer maven repo by updating settings.xml as shown in following xml snippet below. And also add the file to git repo
<settings>
<localRepository>${OPENSHIFT_DATA_DIR}/m2/repository</localRepository>
</settings>
Got to .openshift directory and delete all the files except action_hooks
Go to action_hooks and perform following task
i. Delete README.md
ii. Create deploy file (note the file extension while create should not be txt) and add following code snippet
(It basically creates and downloads and sets up java8 and maven
#!/bin/bash
set -x
if [ ! -d $OPENSHIFT_DATA_DIR/m2/repository ]
then
cd $OPENSHIFT_DATA_DIR
mkdir m2/repository
fi
if [ ! -d $OPENSHIFT_DATA_DIR/jdk1.8.0_51 ]
then
cd $OPENSHIFT_DATA_DIR
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
tar xvf *.tar.gz
rm -f *.tar.gz
fi
if [ ! -d $OPENSHIFT_DATA_DIR/apache-maven-3.3.3 ]
then
cd $OPENSHIFT_DATA_DIR
wget http://mirror.fibergrid.in/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
tar xvf *.tar.gz
rm -f *.tar.gz
fi
cd $OPENSHIFT_REPO_DIR
export M2=$OPENSHIFT_DATA_DIR/apache-maven-3.3.3/bin
export MAVEN_OPTS="-Xms500m -Xmx500m"
export JAVA_HOME=$OPENSHIFT_DATA_DIR/jdk1.8.0_51
export PATH=$JAVA_HOME/bin:$M2:$PATH
mvn -s settings.xml clean install
iii. Add the deploy file to git
iv. Edit start file with following snippet.
#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH
set -x
export JAVA_HOME=$OPENSHIFT_DATA_DIR/jdk1.8.0_51
export PATH=$JAVA_HOME/bin:$PATH
cd $OPENSHIFT_REPO_DIR
nohup java –Xms500m –Xmx500m -jar target/*.jar --server.port=${OPENSHIFT_DIY_PORT} --server.address=${OPENSHIFT_DIY_IP} &
v. Edit stop with following code snippet
#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH
PID=$(ps -ef | grep java.*\.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
client_result "Application is already stopped"
else
kill $PID
fi
vi. Make deploy file executable (Note: This is very important and its common mistake, if not executable your project will not start)
Commit the changes along with your maven src and pom.xml your application should automatically start once the commit is done, Note: for first time it will take time as it needs to download maven repo.
For debuging purpose, its better to add logback.xml in your class path(src/main/resources)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_FILE" value="${OPENSHIFT_LOG_DIR}/kp-apps.log" />
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework.web" level="DEBUG" />

Jenkins on Mac: Cannot run program "pdepend"

Every time I try to run a build, I get a bunch of lines like this:
/Users/Shared/Jenkins/Home/jobs/dghhtreew/workspace/build.xml:28:
The following error occurred while executing this line:
/Users/Shared/Jenkins/Home/jobs/dghhtreew/workspace/build.xml:39: Execute failed: java.io.IOException: Cannot run program "pdepend": error=2, No such file or directory
Here's the relevant part from my build.xml, which was auto-generated by PHP Project Wizard:
...
<target name="parallelTasks" description="Run the pdepend, phpmd, phpcpd, phpcs, phpdoc and phploc tasks in parallel using a maximum of 2 threads.">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpdoc"/>
<antcall target="phploc"/>
</parallel>
</target>
<target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend">
<exec executable="pdepend">
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml
--jdepend-chart=${basedir}/build/pdepend/dependencies.svg
--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg
${source}" />
</exec>
</target>
...
Apparently the Jenkins user cannot find these commands or something. When I log in via the terminal to Jenkins like this:
sudo -s -H -u jenkins
and try pdepend it works as expected. But for some reason it won't work when executed from the Jenkins server. I tried setting absolute paths in the executable line, but I just got the same result. I haven't messed with the install or anything, I have the latest version (1.488) of Jenkins via the mac installer.
Why can't jenkins do anything??
This is an execution path problem with the exec task. Try specifying the entire path to the pdepend command.
<exec executable="/complete/path/to/command/pdepend">
..
Update
If this still doesn't work check the permissions on the pdepend command to ensure that it's executable by the jenkins user.
It's also worth checking the return code when running the pdepend command directly:
sudo -u jenkins /complete/path/to/command/pdepend || echo non-zero return code
Maybe you don't have installed commands, so for me easiest way is via composer:
composer global require 'pdepend/pdepend=*'
If you don't have composer, install it:
curl -sS https://getcomposer.org/installer | php
php composer.phar global require 'pdepend/pdepend=*'
Jenkins let's to ad path variables, you don't need to add paths
Please click "Manage Jenkins"
Click Configure System
Find checkbox "Environment variables" and make sure it is checked
Add new:
name: PATH
value: $PATH:/Users/YOUR_USER/.composer/vendor/bin

Resources