One step in my Azure DevOps pipeline requires Java to be installed on the agent.
I found the "Java Tool Installer" task here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/java-tool-installer?view=azure-devops
This looks, however, more like a SDK installer. I only need a Java runtime environment. I am looking for something like the Python installer task:
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: '3.6'
Is there anything for Java getting close to this?
Is there anything for Java getting close to this?
Test with the Python installer task, this task is used to specify a specific python version via setting the environment.
To achieve a similar purpose with Java, you could set the Java_Home and Path variable during the runtime.
You could add a powershell task at the first step.
Here is an example:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
The $(JAVA_HOME_11_X64) variable is an environment variable.
You could check this variable with the script env | sort. Then the supported value will list in the output.
For example:
In this case, the JAVA_HOME variable will be set as the expected value.
Hope this helps.
Since Azure supports Docker, I would simply go for docker:
trigger:
- main
pr:
- main
- releases/*
pool:
vmImage: 'ubuntu-20.04'
container: adoptopenjdk:latest
steps:
- script: ./gradlew check
Related
I have the Error with pyspark in local when I execute pytest in VS Code from Git Bash.
If I execute pytest from gitbash console:
I try to debug my code when I create the spark Dataframe in Visual code, show me:
Java gateway process exited before sending its port number
I have configured all environment of variables in my PC:
I have seen this error can be my variable Java is not configured really well, but I have checked it is properly.
But if I execute jupyter notebook from git bash, pyspark work really, with this code
enter image description here
It's like the version mismatch causes this. As '_PYSPARK_DRIVER_CALLBACK_HOST' has been removed during version 0.10.7(here) to 2.3, and gets back from version 2.3.1. So, you should check your Spark version, as the SPARK_HOME points to the right one(at least 2.3.1).
from here
I solved it when I put into the .bash_profile file the following line:
export path_java (in my pc)
In this way, when I execute pytest in bash console I pass testing without problems
Although from VS Code I don't pass test with debugger, I can continue with my python library
I have Jenkins node with the below configuration for JavaPath:
/usr/java/jdk1.8.0_131/bin/java
I wrote a simple Jenkins job which prints JAVA_HOME:
#!/bin/ksh
echo "JAVA_HOME=${JAVA_HOME}"
echo $PATH
for some reason, the output I'm getting is:
JAVA_HOME=/usr/java/jdk1.8.0_31
why it doesn't use the value which used to load the node? I don't have such Java reference on the node.
BTW, it's Jenkins container, not VM
There can be a JAVA_HOME configured under Manage Jenkins -> Global Tool Configuration -> JDK. If you provide multiple, you need to specify the Java version that will be used by the build execution.
You can also use existing Java available on the system as well.
For example we have this in pipeline script to identify & print defined tools. tool name is the Name of the JDK defined in Global Tool Configuration:
def jdktool = tool name: 'JDK-1.8.0', type: 'hudson.model.JDK'
env.JAVA_HOME = "${jdktool}"
I'm building a simple hello world application in java (based on spring) which I launch to AWS through a pipeline.
The buildspec.yml is defined as follows:
version: 0.2
phases:
install:
runtime-versions:
java: openjdk8
build:
commands:
- mvn package
artifacts:
files:
- '**/*'
with the appspec.yml as follows:
version: 0.0
os: linux
files:
- source: target/helloworld-1.0-SNAPSHOT.jar
destination: /tmp
hooks:
ApplicationStart:
- location: codedeploy/ApplicationStart.sh
timeout: 60
runas: root
The file codedeploy/ApplicationStart.sh:
#!/usr/bin/env bash
JAR_FILE_HOME='/tmp/helloworld-1.0-SNAPSHOT.jar'
java -jar JAR_FILE_HOME
Weirdly enough the deployment fails with the following error:
Script at specified location: codedeploy/ApplicationStart.sh run as
user root failed with exit code 127
Output log:
[stderr]/opt/codedeploy-agent/deployment-root/5092b759-ecc4-44cb-859a-9823734abc04/d-GVQ6R854B/deployment-archive/codedeploy/ApplicationStart.sh:
line 9: java: command not found
This seems very counter-intuitive since I've installed java in the buildspec.yml. Do I need to install java manually again within the ApplicationStart script or am I doing something else wrong?
CodeBuild doesn't have a link with your application instance instead it only create run time when it receives artifacts for build event.
You don't need to install JAVA run time every time with appspec.yml. I would recommend you to install JAVA run time on an EC2 instance then create an AMI, as a reference base image for future use or you can proceed with Elasticbeanstalk which has prebuilt environments.
The other answer also suggests this but just to clarify:
CodeBuild (specified in buildspec.yml) does the artifact creation. Simply put it takes your code and creates the jar. You defined here the java version. However this has nothing to do with you instance where it will deployed. It is an image where the build happens.
CodeDeploy (specified in appspec.yml) is responsible for deploying the artifact on the instances defined and owned by you. If you created the target instance manually you need to make java available there. As matesio suggested above you could simplify / automate the instance creation with proper java env but that is your responsibility as that is your instance (not like the env used for the build which is configured by AWS in the background)
Currently using VSTS to build Spring Boot applications with Maven. Trying to figure out how to use/get the Maven Version within the build and release process.
Is it possible?
Here is a script that will get the version of maven (given the path) and store the version number in a variable that other tasks can use later in the build.
$mvn = "$Env:M2_HOME\bin\mvn.bat"
$version = (& $mvn -v | select-string -pattern '(Apache\sMaven\s)([^\s]*)').Matches.Groups[2].Value
Write-Output ("##vso[task.setvariable variable=MavenVersion;]$version")
The name of the environment variable is MavenVersion as you can see in the last line. You can use this variable like you would any other environment variable in subsequent scripts or build processes.
I tested this script on the Hosted Build machine, so the path to Maven was under M2_HOME and ended with .bat (Maven 2). You may want to add more code to figure out the path to Maven more generically.
And here is the script in python:
from xml.etree import ElementTree as ET
tree = ET.parse('pom.xml')
#print 'BuildNumber: ', BuildNumber
value =tree.find('./{http://maven.apache.org/POM/4.0.0}version')
print 'Found value:', value.text
print "##vso[task.setvariable variable=POM_VERSION;]", value.text
This is running fine on linux based build agents. The output variable is POM_VERSION.
The cleanest way to do this is like so :
mvn -v | head -1 | cut -d ' ' -f 3
The above snippet will print : 3.8.5 for example
When attempting to start Elasticsearch 5.1.1 via
$ elasticsearch
I get the output:
Error: Could not find or load main class -Xms2g
I've looked into:
I read it may be an error in how a class is called? But I'm not exposed to doing that. This thread doesn't help and isn't really my problem as I'm not installing a plugin.
I installed via Homebrew. Here is some output from that:
$ brew info elasticsearch
elasticsearch: stable 5.1.1, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
Conflicts with: elasticsearch#1.7, elasticsearch#2.4
/usr/local/Cellar/elasticsearch/5.1.1 (98 files, 35.2M) *
Built from source on 2016-12-14 at 09:23:56
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Requirements
Required: java >= 1.8 ✔
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_GabbAHH/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_GabbAHH.log
Plugins: /usr/local/Cellar/elasticsearch/5.1.1/libexec/plugins/
Config: /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/5.1.1/libexec/bin/plugin
To have launchd start elasticsearch now and restart at login:
brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
elasticsearch
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
mongodb
ruby
I also tried originally installing via manually extracting the .tar.gz package. I at first got some Java permission denied errors, but after running a chown to admin for myself I also got this same Error: Could not find or load main class type error.
I just updated my Java JDK to the latest: 1.8.0_112 and set my JAVA_HOME variable to that directory accordingly.
The most recent version of Elasticsearch 2 (2.4.3) works. Meanwhile, Elasticsearch v5.0.2 fails.
What can I do to have Elasticsearch properly installed on my Mac?
Watch out with this line in your .bashrc or similar:
export GREP_OPTIONS='--color=always'
That will break many shell's pipes, so many runners will fail without giving you any clue.
Distros as Ubuntu usually have this enabled by default for system users. Be careful and check that shell environment variable.
This problem was solved on my servers by just unsetting this variable.
You most likely have a problem in your .bash_profile. Usually elastic starts out of the box on a mac.
What I usually do to make upgrading and using multiple projects on my machine is using the following script:
#!/bin/bash
CURRENT_PROJECT=$(pwd)
CONFIG=$CURRENT_PROJECT/config
DATA=$CURRENT_PROJECT/data
LOGS=$CURRENT_PROJECT/logs
BASH_ES_OPTS="-Epath.conf=$CONFIG -Epath.data=$DATA -Epath.logs=$LOGS"
ELASTICSEARCH=$HOME/Development/elastic/elasticsearch/elasticsearch-5.1.1
$ELASTICSEARCH/bin/elasticsearch $BASH_ES_OPTS
Notice the options in BASH_ES_OPTS, these are the ones that changes a lot in version 5. My structure is a folder per project with this script and a few folders: config, data and logs. The config folder contains the files from the elastic distribution: elasticsearch.yml, jvm.properties and log4j2.properties.