I'm trying to use chef to install OpenJDK, as well as downoad Eclipse and install a few plugins using p2 director on a Windows 2008 node. OpenJDK installs and I set my environment variables JAVA_HOME and add it to the path.
However, this change does not take affect until I close and re-open PowerShell. The chef-client run needs these in the current session to run the eclipse p2 director. Is there any way to do this so that I can run chef-client only once?
In my recipe for installing openJDK I included:
env "JAVA_HOME" do
value 'C:\\Program Files\\Zulu\\zulu-8'
end
env "path" do
delim ";"
value '%JAVA_HOME%\\bin'
action :modify
end
#For Command Prompt
execute "setPathCMD" do
command "set PATH=#{node['java']['path']}\\bin;%PATH%"
end
#For PowerShell
powershell_script "setPathPS" do
code <<-EOH
$env:Path="#{node['java']['path']}\\bin;$env:Path"
EOH
end
ENV['Path'] += ";C:\\Program Files\\Zulu\\zulu-8\\bin"
And in the recipe for installing the eclipse plugins I have:
if not node['eclipse']['plugins'].empty?
node['eclipse']['plugins'].each do |plugin_group|
repo, id = plugin_group.first
execute "eclipse plugin install" do
command "#{node['eclipse']['unzip_location']}/eclipse/eclipse.exe -application org.eclipse.equinox.p2.director -noSplash -repository #{repo} -installIUs #{id}"
action :run
end
end
end
Try using setx:
execute 'set java_home' do
command "setx -m JAVA_HOME \"C:\\Program Files\\Zulu\\zulu-8\""
only_if { ENV['JAVA_HOME'] != 'C:\\Program Files\\Zulu\\zulu-8' }
end
# Set JAVA_HOME for this process
ENV['JAVA_HOME'] = 'C:\\Program Files\\Zulu\\zulu-8'
# do something similar for path...
Adapted from the visualstudio cookbook for enabling NuGet package restore:
https://github.com/daptiv/visualstudio/blob/master/recipes/nuget.rb
Put on your client.rb or solo.rb:
ENV['VAR'] = 'value'
Related
I run Poetry in combination together with tox for my unittests.
[tox]
skipsdist = True
envlist = autofix,linters,unittests
isolated_build = True
[testenv:unittests]
commands =
poetry run pytest {posargs: {[pytest-config]posargs}}
I run the tests on my Jenkins Agent, which uses Python 3.9, but I also want to run my tests for Python 3.7 and 3.8.
Does anyone know how to do with Tox and Poetry?
I tried this:
envlist = autofix,linters,{py37,py38,py39}-unittests,pre-commit
but this results in:
C:\Users\xcg5847\Miniconda3\envs\testme\lib\site-packages\tox\config\__init__.py:670: UserWarning: conflicting basepython version (set 3.9, should be 3.7) for env 'py37-unittests';resolve conflict or set ignore_basepython
_conflict
There's a default section in tox, the [testenv] section. Note especially that this does not declare a name. This is the section that is run using the first available, or specifically selected, python executable.
Using the default section with envlist entry below should do the trick:
[tox]
skipsdist = True
envlist = py37,py38,autofix,linters
isolated_build = True
[testenv]
commands =
poetry run pytest {posargs: {[pytest-config]posargs}}
And then tox will use py37 and py38 to run the [testenv] section. Assuming you have autofix,linters defined somewhere below.
Bonus:
Use a envlist = py,autofix,linters configuration. The py will select the first python executable on your PATH. Handy for working with coworkers. And then, in your CI, you can run a dedicated python executable with tox -e py38. Food for thought.
Source
I'm trying to run my test suite on AWS device farm using a custom environment. The test suite runs fine locally but when I run it on device farm some tests fail randomly, and some other acts as expected. Sometimes it looks like it's skipping the cucumber hooks, or just not running the steps.
Here is my custom environment configuration:
# Phases are collection of commands that get executed on Device Farm.
phases:
# The install phase includes commands that install dependencies that your tests use.
# Default dependencies for testing frameworks supported on Device Farm are already installed.
install:
commands:
# By default the ruby version installed is 2.5.1
- mkdir /tmp/tempdir
- export TMPDIR="/tmp/tempdir"
- export TMP="/tmp/tempdir"
- export TEMP="/tmp/tempdir"
- rvm install "ruby-2.6.5"
- rvm use 2.6.5
# you can switch to an alternate ruby version using below command.
#- rvm install 2.3.1 --autolibs=0
# Unpackage and install the gems
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
# Use a pre-configured ruby environment to run your tests.
# This environment has the following gems pre-installed (appium_lib (9.16.1), test-unit (3.2.9)) along with their dependencies.
# If you are using this env, please make sure you do not upload the Gemfile.lock while packaging your tests.
# If the Gemfile.lock contains different versions for the already installed packages, it will ignore the pre-installed packages.
# Using this env can help you speed up your test set up phase as you wont have to install all the gems.
# This default env is only available for ruby 2.5.3.
- rvm gemset use default-ruby-gemset-env-version-1 --create
# Alternatively, you can create a new virtual ruby env using the command:
#- rvm gemset use env --create
# Install the gems from the local vendor/cache directory
- gem install bundler --no-document
- bundle config set path 'vendor/cache'
- gem update --system
- bundle install
# This test execution environment uses Appium version 1.9.1 by default, however we enable you to change it using the Appium version manager (avm). An
# example "avm" command below changes the version to 1.14.2.
# For your convenience, we have preinstalled the following versions: 1.9.1, 1.10.1, 1.11.1, 1.12.1, 1.13.0, 1.14.1, 1.14.2, 1.15.1 or 1.16.0.
# To use one of these Appium versions, change the version number in the "avm" command below to your desired version:
- ln -s /usr/local/avm/versions/1.9.1/node_modules/.bin/appium /usr/local/avm/versions/1.9.1/node_modules/appium/bin/appium.js
# The pre-test phase includes commands that setup your test environment.
pre_test:
commands:
# We recommend starting appium server process in the background using the command below.
# Appium server log will go to $DEVICEFARM_LOG_DIR directory.
# The environment variables below will be auto-populated during run time.
- echo "Start appium server"
- >-
appium --log-timestamp
--default-capabilities "{\"deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \"platformName\":\"$DEVICEFARM_DEVICE_PLATFORM_NAME\",
\"app\":\"$DEVICEFARM_APP_PATH\", \"udid\":\"$DEVICEFARM_DEVICE_UDID\", \"platformVersion\":\"$DEVICEFARM_DEVICE_OS_VERSION\",
\"chromedriverExecutable\":\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\"}"
>> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
# The test phase includes commands that start your test suite execution.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test source code"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- echo "Start Appium Ruby test"
# Modify/Enter the command below to start the tests. The comamnd should be similar to what you use to run the tests locally.
# "bundle exec" is a Bundle command to execute a script in the context of the current bundle.
# For e.g. assuming you run your tests locally using command "ruby YOUR_TEST_FILENAME.rb.", to run your ruby tests using bundle exec command you can use:
- bundle exec rake set_environment[amazon]
- bundle exec rake test
# The post test phase includes are commands that are run after your tests are executed.
post_test:
commands:
# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_LOG_DIR
Here are the cucumber logs(I have tried to use backtrace to get more info but for some reason is not working in AWS)
Start Appium Ruby test
[DeviceFarm] bundle exec rake set_environment[amazon]
[DeviceFarm] bundle exec rake test
Using the test, no_bugs and pretty_progress profiles...
F------
Failing Scenarios:
cucumber -p test -p no_bugs -p pretty_progress features/regression/android/games/lightning.feature:45 # Scenario: Top up modal appears for a user without funds on lightning flow purchase attempts on all or nothing
1 scenario (1 failed)
6 steps (6 skipped)
1m1.742s
Cucumbers failed
I discovered that my capabilities for appium weren't correct and they lacked some capabilities, without them appium and cucumber acts up weirdly, here are the capabilities I used:
caps = {
"automationName": "UiAutomator2",
"platformName": ENV['DEVICEFARM_DEVICE_PLATFORM_NAME'],
"deviceName": ENV['DEVICEFARM_DEVICE_NAME'],
"app": ENV['DEVICEFARM_APP_PATH'],
"uuid": ENV['DEVICEFARM_DEVICE_UDID'],
"appPackage": "appPackageOfYourChoice",
"appActivity": "appActivityOfYourChoice",
"autoGrantPermissions": true
}
I have this code where execute is a Chef resource:
execute 'phpbrew_0' do
command 'phpbrew --verbose install 5.6 +apxs2'
end
execute 'phpbrew_1' do
command 'phpbrew --verbose install 7.0 +apxs2'
end
execute 'phpbrew_2' do
command 'phpbrew --verbose install 7.1 +apxs2'
end
Does ruby have this feature where I can provide a collection of command and have them all be passed to the execute resource. Something like Javascript's Array.map?
Yep, Hash#each, for example: https://ruby-doc.org/core-2.4.1/Hash.html#method-i-each
resource_to_command = {
'phpbrew_14' => 'phpbrew --verbose install 5.6 +apxs2',
'foo' => 'bar'
}
resource_to_command.each do |resource, cmd_text|
execute resource do
command cmd_text
end
end
I am trying to install my .exe after downloading them into:
wget "https://github.com/git-for-windows/git/releases/downloadv2.13.1.windows.2/Git-2.13.1.2-64-bit.exe" -outfile c:\Windows\System32\Bradford\Git-2.13.1.2-64-bit.exe
However, when I try to install it silently, without human interaction:
C:\Windows\System32\Bradford\Git-2.13.1.2-64-bit.exe /s /v"/qn"
I am getting this error:
The system cannot find the path specified.
Also I do not know how to install a .msi file silently as well. In this case, nodeJS
I am using a AWS instance instance. Specifically:
Microsoft Windows Server 2012 R2 with SQL Server Express - ami-37b39552
Microsoft Windows Server 2012 R2 Standard edition, 64-bit architecture, Microsoft SQL Server 2016 Express edition. [English]
The easiest way I know how to do this is with Chocolatey.
I have some cloud servers that need various Chocolatey packages, and I do (something like) the following to install them. I have installed Git this way before, and it is a completely unattended / silent install.
Here's a short script that handles installing and configuring Chocolatey, installing Git, and updating the %PATH%.
<#
.description
Get the PATH environment variables from Machine, User, and
Process locations, and update the current Powershell
process's PATH variable to contain all values from each of
them. Call it after updating the Machine or User PATH value
(which may happen automatically during say installing
software) so you don't have to launch a new Powershell
process to get them.
#>
function Update-EnvironmentPath {
[CmdletBinding()] Param()
$oldPath = $env:PATH
$machinePath = [Environment]::GetEnvironmentVariable("PATH", "Machine") -split ";"
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User") -split ";"
$processPath = [Environment]::GetEnvironmentVariable("PATH", "Process") -split ";"
$env:PATH = ($machinePath + $userPath + $processPath | Select-Object -Unique) -join ";"
Write-EventLogWrapper -message "Updated PATH environment variable`r`n`r`nNew value: $($env:PATH -replace ';', "`r`n")`r`n`r`nOld value: $($oldPath -replace ';', "`r`n")"
}
# Install Chocolatey itself:
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
# NOTE: Chocolatey changes the system %PATH%, so we have to get the latest update here:
Update-EnvironmentPath
# Configure Chocolatey to not require confirmation when installing packages:
choco.exe feature enable --name=allowGlobalConfirmation --yes
# Install the package we care about
choco.exe install git
# Installing Git also changes the system %PATH%, so we have to update it again:
Update-EnvironmentPath
C:\Work\R contains the R-3.1.1.tar.gz file
I have build R source(R-3.1.1) in windows 8 from the following commands
cd C:\Work\R
tar --no-same-owner -xf R-3.1.1.tar.gz
cd C:\Work\R\R-3.1.1\src\gnuwin32\
make all recommended
Add the following path to the Environment variables
C:\Work\R\R-3.1.1\bin\i386
Enter the R.exe in command promt
I got the following Error
Fatal error unable to open the base package
System information
Windows 8, 64 bit operating System, x64 –based processor
How to resolve this error?
If you are using R, you can download the newest version from here and then simply install it.
If you have an older version and want only to download the new one, use those commands inside R:
# installing/loading the package:
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr
# using the package:
updateR() # this will start the updating process of your R installation. It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.
We can resolve this issue by using the following command before build the R source code
Set TMPDIR=c:\cygwin64\bin
Here c:\cygwin64\bin is the cygwin installed location in Windows 8 machine.
Here I have mentioned the R source code build steps:
Install cygwin setup
Install RTools
Create the R_HOME file in the directory like C:\R_HOME
Place the R source code tar file in the R_HOME
Add the following path in environment variable in first
c:\Rtools\bin\;c:\Rtools\gcc-4.6.3\bin;C:\cygwin64\bin\;C:\Program Files (x86)\HTML Help Workshop\;C:\R_HOME\R-3.1.1\bin\;
Enter the following command in the command prompt
Set TMPDIR=C:\cygwin64\bin
Set working directory as C:\R_HOME
Enter the following command
tar --no-same-owner -xf R-3.1.1.tar.gz
Copy the Tcl source from c:\R (it will be created while installing RTools)
Set the working directory as follow in command prompt
C:\R_HOME\R-3.1.1\src\gnuwin32
Enter the following command
Make all recommended
Enter the R.exe command in command prompt. We can enter the R terminal