Schedule or trigger jobs in gitlab-ci - gitlab-ci

I want to run a heavy test only once per day in Gitlab-ci. Is it possible schedule a job? Or is it possible to set it to manual and trigger it using the API?

It's possible to schedule a pipeline since GitLab 9.1, see:
https://docs.gitlab.com/ce/user/project/pipelines/schedules.html
Currently (i.e. with version 9.2) it can be configured as follows:
Navigate to your project's Pipelines ➔ Schedules and click the New Schedule button.
Fill in the form
Hit Save pipeline schedule for the changes to take effect.

It's a patch up job, but you could use triggers with a if statement :
test_app:
stage: test
script:
- if [ -n "${DO_TESTS}" ]; then make test; fi
And define the variable in the cron that make the call :
curl --request POST \
--form token=TOKEN \
--form ref=master \
--form "variables[DO_TESTS]=true" \
https://gitlab.example.com/api/v3/projects/9/trigger/builds
See the doc : https://docs.gitlab.com/ce/ci/triggers/README.html

This is possible, and will be improved in GitLab 11.6 (Dec. 22nd)
See gitlab-org/gitlab-ce issue 20422:
Currently all variables are shown in UI:
http://docs.gitlab.com/ce/ci/triggers/README.html#pass-build-variables-to-a-trigger
This is sometimes problematic, e.g. when you pass individual secrets to the build, which could not be placed in a protected variable and should not be visible to all team members.
It can also be problematic even for some non-protected variables if they are unintentionally passed around in a screenshot/screen sharing.
Proposal
Variable names will still be visible by default
Variables values will be censored by default with asterix *******
Variable values are toggle-able with a button
The button is only available to maintainers

Related

how to pass value from commit to GitLab CI pipeline as variable?

I need to dynamically pass value to GitLab CI pipeline to pass the value further to jobs. The problem is: the value cannot be stored in the code and no pipeline reconfiguration should be needed (e.g. I can pass the value in "variables" section of .gitlab-ci.yml but it means store value in the code, or changes in "Environment variables" section of "CI / CD Settings" means manual reconfiguration). Also, branch name cannot be used for that purpose too.
It is not a secret string but a keyword which modifies pipeline execution.
So, how can I do it?
You didn't specify the source of this value.
You say "pass value from commit to ..."
If it's some meta information about the commit itself, look at the list of Predefined environment variables
There's quite a lot of vars named CI_COMMIT_* which might work for you.
However,
if it's some value that you generate in the pipeline in one job and want to pass to another job - it's a different case.
There is a long-living request to Pass variables between jobs, which is still not implemented.
The workaround for this moment is to use artifacts - files to pass information between jobs in stages.
Our use case is to extract Java app version from pom.xml and pass it to some packaging job later.
Here is how we do it in our .gitlab-ci.yml:
...
variables:
VARIABLES_FILE: ./variables.txt # "." is required for image that have sh not bash
...
get-version:
stage: prepare
image: ...
script:
- APP_VERSION=...
- echo "export APP_VERSION=$APP_VERSION" > $VARIABLES_FILE
artifacts:
paths:
- $VARIABLES_FILE
...
package:
stage: package
image: ...
script:
- source $VARIABLES_FILE
- echo "Use env var APP_VERSION here as you like ..."

How to use Bamboo plan variables in an inline script task?

When defining a Bamboo plan variable, the page has this.
For task configuration fields, use the syntax
${bamboo.myvariablename}. For inline scripts, variables are exposed as
shell environment variables which can be accessed using the syntax
$BAMBOO_MY_VARIABLE_NAME (Linux/Mac OS X) or %BAMBOO_MY_VARIABLE_NAME%
(Windows).
However, that doesn't work in my Linux inline script. For example, I have the following defined a a plan variable
name: my_plan_var value: some_string
My inline script is simply...
PLAN_VAR=$BAMBOO_MY_PLAN_VAR
echo "Plan var: $PLAN_VAR"
and I just get a blank string.
I've tried this
PLAN_VAR=${bamboo.my_plan_var}
But I get
${bamboo.my_plan_var}: bad substitution
on the log viewer window.
Any pointers?
I tried the following and it works:
On the plan, I set my_plan_var to "it works" (w/o quotes)
In the inline script (don't forget the first line):
#/bin/sh
PLAN_VAR=$bamboo_my_plan_var
echo "testing: $PLAN_VAR"
And I got the expected result:
testing: it works
I also wanted to create a Bamboo variable and the only thing I've found to share it between scripts is with inject-variables like following:
Add to your bamboo-spec.yaml the following after your script that will create the variable:
Build:
tasks:
- script: create-bamboo-var.sh
- inject-variables:
file: bamboo-specs/vars.yaml
scope: RESULT
# namespace: plan
- script: echo ${bamboo.inject.GIT_VERSION} # just for testing
Note: Namespace defaults to inject.
In create-bamboo-var.sh create the file bamboo-specs/vars.yaml:
#!bin/bash
versionStr=$(git describe --tags --always --dirty --abbrev=4)
echo "GIT_VERSION: ${versionStr}" > ./bamboo-specs/vars.yaml
Or for multiple lines you can use:
SW_NUMBER_DIGITS=${1} # Passed as first parameter to build script
cat <<EOT > ./bamboo-specs/vars.yaml
GIT_VERSION: ${versionStr}
SW_NUMBER_APP: ${SW_NUMBER_DIGITS}
EOT
Scope can be local or result. Local means it's only available for current job and result means it can be used in subsequent stages of this plan and releases that are created from the result.
Namespace is just used to avoid naming collisions with other variables.
With the above you can use that variable in later scripts with ${bamboo.inject.GIT_VERSION}. The last script task is just to see that it is working in other scripts. You can also see the variables in the web app as build meta data.
I'm using the above script before the build (in my case compiling C-Code) takes place so I can also create a version.h file that can be used by the source code.
This is still a bit cumbersome but I'm happy with it and I hope it will help others to configure Bamboo. Bamboo documentation could be better. (Still a lot try and error)

How to include Doxygen method description in Xcode's autocomplete popup?

Using Xcode , I want to have the Doxygen description of my method below the autocomplete option, like alloc:
When writing, Xcode displays the autocomplete with the comments from the documentation. You can see in the image for example, when alloc is selected from the options, it says "Returns a new instance of the receiving class" and also links to the documentation.
I have been able to document my source code with Doxygen, for instance
/**
This does nothing
*/
-(void) doNothing
{
// This does nothing
}
and I get the expected results in the HTML file that Doxygen generates, yet I don't know how to make those results appear as suggestions in Xcode.
Good news everyone! Xcode 5 now has built-in support for DOxygen style comments. So, you can comment your methods like this:
/*!
* Provides an NSManagedObjectContext singleton appropriate for use on the main
* thread. If the context doesn't already exist it is created and bound to the
* persistent store coordinator for the application, otherwise the existing
* singleton contextis returned.
* \param someParameter You can even add parameters
* \returns The a shared NSManagedObjectContext for the application.
*/
+ (NSManagedObjectContext *)sharedContext;
Inline help will look like this:
Quick help will look like this:
And sidebar help will look like this:
Here's a handy code snippet you can add the your Xcode Code Snippet library to make method documentation simple:
/**
<#description#>
#param <#parameter#>
#returns <#retval#>
#exception <#throws#>
*/
Now, you can just type "doxy" and poof! You have your doxygen template.
What I have found to be better than a code snippet for Doxygen/Javadoc style comments is using VVDocumenter-Xcode Plugin It is great! After installing you can simply type "///" above any code you want commented and it will grab the parameters and return as well add placeholders for you to complete your comment block.
I was able to achieve what I wanted using Appledocs, although I fought a bit with installation and setup...
Open xCode and go to xCode> Preferences > Downloads and download the 'Command Line Tools' in case you don't have it.
Open up terminal and type
git clone git://github.com/tomaz/appledoc.git
When it's done go to the appledoc folder, type
cd appledoc
and install appledoc into your usr/local/bin folder with this command:
sudo sh install-appledoc.sh
Open any xCode project and go to the package explorer on the left, and click on your main project file (the one that has the amount of targets and the sdk version detailed below)
In the Build settings tab, look below for '+Add Target' button and open it
Choose the 'Aggregate' template (make sure you choose iOS or macosx depending on your project and name it 'Documentation'
Select Documentation, go to Build Phases tab, and below click 'Add Build Phase' and select Add Run Script.
Copy and paste the code below on the Run Script field:
#appledoc Xcode script
# Start constants
company="ACME";
companyID="com.ACME";
companyURL="http://ACME.com";
#target="iphoneos";
target="macosx";
outputPath="~/help";
# End constants
/usr/local/bin/appledoc \
--project-name "${PROJECT_NAME}" \
--project-company "${company}" \
--company-id "${companyID}" \
--docset-atom-filename "${company}.atom" \
--docset-feed-url "${companyURL}/${company}/%DOCSETATOMFILENAME" \
--docset-package-url "${companyURL}/${company}/%DOCSETPACKAGEFILENAME" \
--docset-fallback-url "${companyURL}/${company}" \
--output "${outputPath}" \
--publish-docset \
--docset-platform-family "${target}" \
--logformat xcode \
--keep-intermediate-files \
--no-repeat-first-par \
--no-warn-invalid-crossref \
--exit-threshold 2 \
"${PROJECT_DIR}"
In the start constants, you can replace names and such, also make sure to use the proper target (iOS or macosx)
Finally, go to Product > Scheme > Edit Scheme > Build Tab and add your 'Documentation' Target, make sure every box is checked. This way each time you build your code your documentation gets updated.
And that's it, you are good to go and start documenting your code.
Note that although the documentation updates each time you build, the popover suggestions won't update until you restart Xcode.
For proper documentation techniques, read this article

How do I add a heroku deployhook:email using API?

I have been able to add a deployhook (for email and IRC) using the heroku cli (sdk). I would like to be able to add or update the email values (receipient etc) using the API. Is this possible? When I try to curl request to add a hook I get an error message noting the need for extra data: receipient, body, etc.
You can find a bit more detail about the different arguments here: https://devcenter.heroku.com/articles/deploy-hooks#email
Once you know what values you want/need you should be able to send it using this:
curl -n -g -X POST 'https://api.heroku.com/apps/MYAPP/addons/deployhooks%3Aemail?config[recipient]=me#example.com&config[subject]="MYAPP%20Deployed"&config[body]="{{user}}%20deployed%20app"'
The arguments:
-n reads credentials from netrc (this should be set by the toolbelt/cli)
-g tells it to not try and interpret the [] and {} in the url
-X POST sets it to be a POST rather than get request
Beyond that it was just a matter of encoding the params properly. I believe of those values recipient is the only required value (and the others have reasonable defaults).
You can only have one deployhook per type and they don't appear to allow updates. So if you need to change it, you'll want to remove the old one and then add another with the updated attributes. You can remove the old one like this:
curl -n -X DELETE 'https://api.heroku.com/apps/MYAPP/addons/deployhooks%3Aemail'

Zsh trouble when using echo with color/formatting characters

I'm just switch to zsh and now adapting the alias in which was printing some text (in color) along with a command.
I have been trying to use the $fg array var, but there is a side effect, all the command is printed before being executed.
The same occur if i'm just testing a echo with a color code in the terminal:
echo $fg_bold[blue] "test"
]2;echo "test" test #the test is in the right color
Why the command print itself before to do what it's supposed to do ? (I precise this doesn't happen when just printing whithout any wariable command)
Have I to set a specific option to zsh, use echo with a special parameter to get ride of that?
Execute the command first (keep its output somewhere), and then issue echo. The easiest way I can think of doing that would be:
echo $fg[red] `ls`
Edit: Ok, so your trouble is some trash before the actual output of echo. You have some funny configuration that is causing you trouble.
What to do (other than inspecting your configuration):
start a shell with zsh -f (it will skip any configuration), and then re-try the echo command: autoload colors; colors; echo $fg_bold[red] foo (this should show you that the problem is in your configuration).
Most likely your configuration defines a precmd function that gets executed before every command (which is failing in some way). Try which precmd. If that is not defined, try echo $precmd_functions (precmd_functions is an array of functions that get executed before every command). Knowing which is the code being executed would help you search for it in your configuration (which I assume you just took from someone else).
If I had to guess, I'd say you are using oh-my-zsh without knowing exactly what you turned on (which is an endless source of troubles like this).
I don't replicate your issue, which I think indicates that it's either an option (that I've set), or it's a zsh version issue:
$ echo $fg_bold[red] test
test
Because I can't replicate it, I'm sure there's an option to stop it happening for you. I do not know what that option is (I'm using heavily modified oh-my-zsh, and still haven't finished learning what all the zsh options do or are).
My suggestions:
You could try using print:
$ print $fg_bold[red] test
test
The print builtin has many more options than echo (see man zshbuiltins).
You should also:
Check what version zsh you're using.
Check what options (setopt) are enabled.
Check your ~/.zshrc (and other loaded files) to see what, if any, options and functions are being run.
This question may suggest checking what TERM you're using, but reading your question it sounds like you're only seeing this behaviour (echoing of the command after entry) when you're using aliases...?